2

大家好,我正在从事一个处理事件现场的项目。我正在尝试在有人注册后更新事件点的值。有人注册或读取数据库中的值没有问题,但我无法更新这些点。希望你能帮忙。。

这是代码的不工作部分:

$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 行中的值。

4

3 回答 3

3

在失踪者旁边'

您可以直接在查询中执行更改:

UPDATE `events`
SET    `free_spots` = `free_spots`-1,
       `full_spots` = `full_spots`+1
WHERE  `event_id`   = :event_id

您还需要绑定 :event_id 占位符 $update_event_query_do->bindParam(':event_id', $event_id, PDO::PARAM_INT);

于 2012-09-01T14:01:06.637 回答
0

没有引号 $update_event_query_do -> bindParam(':full_spots, $full_spots_new, PDO::PARAM_INT);

尝试一下:

$update_event_query_do -> bindParam(':full_spots', $full_spots_new, PDO::PARAM_INT);
于 2012-09-01T13:58:40.787 回答
0

你没有绑定:event_id你的参数......

于 2012-09-01T14:02:35.050 回答