Sunday, August 19, 2012

mysqli – Date and time from PHP writes 0000-00-00 00:00:00 in MySQL

I have a PHP with a JS datepicker for date and time that save all the string in this format \”19.08.2012 @ 20:18\” in a a variable called $date.


If I place this variable directly in the query, it writes \”0000-00-00 00:00:00\” in the database.

At the moment I have a big black hole in my head, so need help.


How can I write the correct selected date and time in the database?




Sorry I thought not so important, here is the code.


index.php



<script type=\"text/javascript\">
$(function() {
$(\"#date\").datetimepicker({
dateFormat:\'dd.mm.yy\',
separator: \' @ \'
});
});
</script>

<form action=\"setting.php\" method=\"post\">
<table>
<tr>
<td><label for=\"date\">Date:</label></td>
<td><input type=\"text\" id=\"date\" name=\"date\"/></td>
</tr>
</table>
<input type=\"submit\" name=\"submit\" />


setting.php



if(isset($_POST[\'save_autoresp\'])) {
create($_POST[\'date\']);
header(\"Location: admin.php\");
exit();
} else {
header(\"Location: index.php\");
exit();
}


functions.php



.......
.......
// Write the fields to the table
$query_create = mysqli_query($link, \"INSERT INTO table VALUES (null, \'$id\', \'$date\')\") or die (\'Could not connect: \' . mysqli_error($link));
.......
.......


The date field in teh MySQL database is \”datetime\”.






Rating: 4 out of 5 based on 3 ratings



The post mysqli – Date and time from PHP writes 0000-00-00 00:00:00 in MySQL appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/mysqli-date-and-time-from-php-writes-0000-00-00-000000-in-mysql.html

No comments:

Post a Comment