-1

一直在修改我的网站,它是一个座位预订网站。由于明显的原因,仍然处于 alpha 测试中,所以还没有向公众展示。

但是,我在更新数据库中的值时遇到了一些问题。

我将发布代码然后解释问题..

     else {

   $seatID = $_POST['form_submitted'];

$query1 = "SELECT seatTaken FROM SEATS WHERE seatNo = '$seatID'";
            $result = mysql_query($query1);  
            while($row = mysql_fetch_array($result))
            {
               $taken = $row['seatTaken'];  
            }


$query2 = "SELECT passNo FROM PASSENGER WHERE username = '$loggedinuser'";
            $result = mysql_query($query2);  
            while($row = mysql_fetch_array($result))
            {
               $passno = $row['passNo'];  
            }


$query3 = "SELECT groupID FROM PASSENGER WHERE username = '$loggedinuser'";
            $result = mysql_query($query3);  
            while($row = mysql_fetch_array($result))
            {
               $groupno = $row['groupID'];  
            }

$query4 = "SELECT flightNo FROM PASSENGER WHERE username = '$loggedinuser'";
            $result = mysql_query($query3);  
            while($row = mysql_fetch_array($result))
            {
               $flightno = $row['flightNo'];  
            }


  // if ($taken = 0) {

 $update = mysql_query("UPDATE PASSENGER SET seatNo = $seatID WHERE username = '$loggedinuser'");
 $update2 = mysql_query("UPDATE SEATS SET seatTaken = 1, passNo = '$passNo', groupID = '$groupid' WHERE seatNo = '$seatID'");
 // AND flightNo = '$flightno'"
   echo '<meta http-equiv="refresh" content="5;url=http://www.mywebsite.com/">';
       echo mysql_error();

  //}

 }

 ?>

现在用户将在以前的表单中选择他们的座位,因此:

 $seatID = $_POST['form_submitted'];

但是,在我的查询的底部,运行此 PHP 代码时数据库中实际更改的唯一值是“seatTaken”的布尔值,因为它确实从 0(未占用)更改为 1(已占用)。

我的数据库中的字段 passNo 和 groupID 不更新这些查询中引用的此处:-

 $update = mysql_query("UPDATE PASSENGER SET seatNo = $seatID WHERE username =     '$loggedinuser'");
 $update2 = mysql_query("UPDATE SEATS SET seatTaken = 1, passNo = '$passNo', groupID = '$groupid' WHERE seatNo = '$seatID'");

有人能帮忙吗?非常感谢!

汤姆

4

2 回答 2

1

注意你的变量命名和字符串引用

当您在 mysql 中查找值时,它们通常需要是字符串文字(添加引号)。你的另一个问题是你的变量名:

$update = mysql_query("UPDATE PASSENGER SET seatNo = '$seatID' WHERE username = '$loggedinuser'");
$update2 = mysql_query("UPDATE SEATS SET seatTaken = 1, passNo = '$passno', groupID = '$groupno' WHERE seatNo = '$seatID'");
  • $passno 与 $passNo
  • $groupid 与 $groupno

您还应该确保正确转义来自用户http://php.net/manual/en/function.mysql-real-escape-string.php的任何输入

于 2012-04-07T14:45:31.950 回答
0

在您的代码中看不到如何生成 $groupid、$passNo、$seatID 的值。更新时是否设置了这些变量?(只需回显 SQL 代码即可查看正在向您的数据库发送什么查询)

如果 groupid 是表单中字段的名称,也许您应该尝试从您的发布请求中获取变量,例如 $_POST['groupid']。

于 2012-04-07T14:41:32.943 回答