I'm trying to update a sql datetime. I just wana update the time and have some scripts for substr(). Now when i update the Hrs and min the day (d) get's reset to 1 in the first edit and 0 in a second edit.
I'm using a html table generated by php and bootstrap-editable for editing the rows using Js and PHP.
Why does the date return first 01 and then 00 in db?
Ex. 2012-02-23 00:00:00 becomes 2012-02-01 00:00:00 in first update.
HTML
<a href='#' id='".$row['id']."' class='usr_stamp_out' data-name='usr_stamp_out' data-type='text' data-pk='".$row['id']."' data-url='php/time.php' data-title='Stämpla ut..'>".substr($row['usr_stamp_out'],11,5)."</a>
PHP
$id = $_POST['pk'];
$updated_usr_stamp_out = $_POST['value'];
if($row){
//Substring datetime to 0000-00-00
$usr_stamp_out_date = substr($row['usr_stamp_out'],0,9);
//Add old date to updated time
$new_usr_stamp_out = $usr_stamp_out_date." ".$updated_usr_stamp_out;
//Prepare query
$query = "UPDATE table SET usr_stamp_out = :usr_stamp_out WHERE id = :id";
// Security measures
$query_params = array(':id' => $id,':usr_stamp_out' => $new_usr_stamp_out);
//Connect and execute
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex){
die("Failed to run query: " . $ex->getMessage());
}
}