大家好,我正在从事一个处理事件现场的项目。我正在尝试在有人注册后更新事件点的值。有人注册或读取数据库中的值没有问题,但我无法更新这些点。希望你能帮忙。。
这是代码的不工作部分:
$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__));
}
也可以在不定义新变量(如 $free_spots_new exc)的情况下更新 UPDATE 行中的值。