Hello guys im working on a project for handling spots on a event. I'm trying to update the values of the event spots after someone registers to it. There is no problem with someone registering or reading the values from database but i cant update the spots. Hope you can help..
Here is the not working part of the code :
$free_spots_new = $free_spots - 1 ; // i haven't written the code up there, $free_spots is the value of the free_spots value in the database. And this is the process after someone registers to this event ...
$full_spots_new = $full_spots + 1 ; // same in here
try{
$update_event_query = "UPDATE `events` SET `free_spots` = :free_spots, `full_spots`= :full_spots WHERE `event_id`=:event_id";
$update_event_query_do = $db->prepare($update_event_query);
$update_event_query_do -> bindParam(':free_spots', $free_spots_new, PDO::PARAM_INT);
$update_event_query_do -> bindParam(':full_spots', $full_spots_new, PDO::PARAM_INT);
$update_event_query_do ->execute() or die(print_r($update_event_query_do->errorInfo(), true));
}
catch(PDOException $e) {
$log->logError($e." - ".basename(__FILE__));
}
Also is it possible to update the values within the UPDATE line without defining a new variable like $free_spots_new exc.
Beside the missing
'
You can execute the alterations directly in the query:
Your also need to bind the :event_id placeholder
$update_event_query_do->bindParam(':event_id', $event_id, PDO::PARAM_INT);