php - inserting dates into mysql database -
i have simple form has hidden field value of:
<?php echo date('y-m-d'); ?>
when submit form via php processing script on form goes database apart date.
here sql:
$sql = "insert wp_reminders (dateofentry, ipaddress, type) values ('$_post[dateofentry]','$_post[ipaddress]' ,'$_post[type]')";
when echo date out on processing page shows fine.
i have setup column in database following:
dateofentry date not null
any ideas if there wrong above?
any dates inserted mysql must conform one of formats mysql can parse or must converted. iso 8601 preferred format, yyyy-mm-dd hh:mm:ss
typically.
if used pdo:
$sql = "insert wp_reminders (dateofentry, ipaddress, type) values (:dateofentry, :ipaddress, :type)"; $statement = $pdo->prepare($sql); $statement->bindparam(":dateofentry", strtotime(date("y-m-d h:i:s")), pdo::param_str); $statement->bindparam(":ipaddress", $_post['ipaddress'], pdo::param_str); $statement->bindparam(":type", $_post['type']), pdo::param_str); $statement->execute();
unless you're expecting forms take long time process, might create sense supply date @ time of query creation. if not, can set strtotime
phone call form instead.
php mysql
No comments:
Post a Comment