Hi everyone,
My table "list" contains one field: "exam_date" of type "datetime".
Dates in that table are formatted by the following structure: "2014-08-31 21:45:47" (yyyy-mm-dd hh:ii:ss).
In my input form date is assigned the following way:
In order to see the value assigned I added to my code:
On the display i see the date inserted by the following structure:31-08-14 21:45:47.
My code to insert the new value to the table is:
When I run it i get: "no record added" and when I check the table I see that no record was added indeed.
I belive that the reason for not able to add a record is the difference in date structures' that of the table and that of the input.
Can I change the date structure in the table to "dd-mm-yy hh:ii:ss"?
Is there a way to convert the input structure from "dd-mm-yy hh-ii-ss" to "yyyy-mm-dd hh:ii:ss"?
Thanks !
My table "list" contains one field: "exam_date" of type "datetime".
Dates in that table are formatted by the following structure: "2014-08-31 21:45:47" (yyyy-mm-dd hh:ii:ss).
In my input form date is assigned the following way:
Code:
<input id="exam_date" name="exam_date" type="datetime" placeholder="<?php echo date('d-m-y H:i:s'); ?>">
Code:
$myDate = trim($_POST['exam_date']);
echo trim($_POST['exam_date']);
My code to insert the new value to the table is:
Code:
<?php
date_default_timezone_set('xxx');
$dbcon = @mysqli_connect ('xxx', 'xxx', 'xxx', 'test') OR die ('Could not connect to MySQL: ' . mysqli_connect_error () );
mysqli_set_charset($dbcon, 'utf8');
if (isset($_POST['exam_date']))
{
$myDate = trim($_POST['exam_date']);
echo $myDate ;
$q = "INSERT INTO list (exam_date) VALUES ($myDate)";
$result = @mysqli_query ($dbcon, $q);
if($result)
{
echo "record added";
}
else
{
echo "no record added !";
}
}
?>
<form action="add_date.php" method="post">
<input id="exam_date" name="exam_date" type="datetime" placeholder="<?php echo date('y-m-d H:i:s'); ?>">
<input id="submit" type="submit" name="submit" value="Register">
</form>
I belive that the reason for not able to add a record is the difference in date structures' that of the table and that of the input.
Can I change the date structure in the table to "dd-mm-yy hh:ii:ss"?
Is there a way to convert the input structure from "dd-mm-yy hh-ii-ss" to "yyyy-mm-dd hh:ii:ss"?
Thanks !