执行MySQL UPDATE查询但不更新表

时间:2013-07-26 14:02:21

标签: php mysql

if(isset($_POST['select4']))
{$roomdes=$_POST['select4'];}
if(isset($_POST['select5']))
{$roomid=$_POST['select5'];}
$roomid=mysql_real_escape_string('$roomid');
$roomdes=mysql_real_escape_string('$roomdes');

if(isset($_POST['button2']))

{
$sql2="UPDATE master_table SET Room_booked=1 WHERE Room_type='$roomdes' AND Room_id='$roomid'";
$res3=mysql_query($sql2);
echo"done";
echo $sql2;
if(!$res3)
{echo"not being updated";}
else echo" \nupdatedddd\n";

}

此处更新已打印但我的表不会更新。我该怎么办?

1 个答案:

答案 0 :(得分:2)

$roomid=mysql_real_escape_string('$roomid');
$roomdes=mysql_real_escape_string('$roomdes');

应该是:

$roomid=mysql_real_escape_string($roomid);
$roomdes=mysql_real_escape_string($roomdes);

当它们被包含在撇号中时(即'),PHP假定字符串不是变量。

您还可以尝试以下操作来查看更新它是否有错误:

 $res3 = mysql_query($sql2) or die(mysql_error());