Andy Andy - 8 months ago 65
MySQL Question

Why does this MySQL Update query not work?

Here is my code for updating the date field for all records that have the field WorkoutID = $currentWorkoutID. When I run the query the dates change to 0000-00-00 and not to the current date. How can I fix this? Btw DB::getInstance() executes the query. I think something is wrong with the actual query?

$currentWorkoutID = $_SESSION['GlobalWorkoutID'];
echo $currentWorkoutID;

$date = date("y/m/d");
echo $date;

$sql = "UPDATE workout SET Date = ".$date." WHERE WorkoutID = ".$currentWorkoutID."";

Answer Source

include single quotes ' for date

$sql = "UPDATE workout SET Date = '".$date."'  WHERE WorkoutID = ".$currentWorkoutID."";
                                  ^         ^