简体   繁体   English

用php代码更新phpmyadmin中的记录

[英]Updating record in phpmyadmin with php code

I have a reservation form where once it is filled out, the rooms available for a certain building are decreased by one. 我有一个预订表格,一旦填写完毕,某栋建筑物的可用房间就会减少一间。 I am using Cloud9 ide with php to update the record for that building in the phpmyadmin database. 我将Cloud9 ide与php一起使用,以更新phpmyadmin数据库中该建筑物的记录。 I think the equation to subtract one room from roomsAvailable is not being read. 我认为未读取从roomsAvailable中减去一个房间的方程式。 It might be as simple as an issue with quotes. 这可能和引号一样简单。

This is the update: 这是更新:

$sql = "UPDATE $dormTable SET roomsAvailable = --$dormRecord[roomsAvailable] 
        WHERE id = $dormRecord[id]";

This is the output on the webpage when i echo the statement and the dorm record: 当我回显该语句和宿舍记录时,这是网页上的输出:

"UPDATE `dorms` SET `roomsAvailable` = --5 WHERE `id` = 8"

Array ( [id] => 8 [name] => Lower West Cedar St. [class] => 2 [specialNeeds] => 1 [laundry] => 1 [fullyEquippedKitchen] => 1 [roomsAvailable] => 5 [roomsReserved] => 0 [roomCapacity] => 5 )

我认为这将是更好的解决方案

$sql = "UPDATE dorms  SET roomsAvailable = roomsAvailable-1 WHERE id = $dormRecord[id]";

If you need the value of --$dormRecord[roomsAvailable] you shuold use string concatenation for $sql 如果您需要-$ dormRecord [roomsAvailable]的值,则应该对$ sql使用字符串连接

In this way the php code is execute and the result is concatenated with query 这样,将执行php代码,并将结果与​​查询连接在一起

$sql = "UPDATE $dormTable SET roomsAvailable = "  .  --$dormRecord[roomsAvailable]  .
     "  WHERE id = $dormRecord[id]";

you can see thye result using 您可以使用查看结果

echo  $sql ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM