lalthung lalthung - 4 months ago 11
SQL Question

unable to update datetime field, value becomes 0000:00:00 00:00:00

what is it that im doing wrong that datetime field is not getting updated and instead the value becomes all 0

echo print_r($_POST);;
$time_in = $_POST['time_in'];
$time_out = $_POST['time_out'];

$id = $_GET['id'];

echo $sql = "UPDATE hours SET time_in = '".$time_in."' AND time_out = '".$time_out."' WHERE id = '".$id."'";
mysql_query($sql) or die(mysql_error());

Answer

use following code

echo print_r($_POST);;
$time_in = date('Y-m-d H:i:s',strtotime($_POST['time_in']));
$time_out = date('Y-m-d H:i:s',strtotime($_POST['time_out']));

$id = $_GET['id'];

echo $sql = "UPDATE hours SET time_in = '".$time_in."' AND time_out = '".$time_out."' WHERE id = '".$id."'";
mysql_query($sql) or die(mysql_error());