MySQL Update没有设置新标志

时间:2014-10-02 13:31:38

标签: mysql

我不知道为什么但更新不起作用,任何想法? 在正常情况下,它应该检查代码输入是否有效(代码)之后它应该将行“used”设置为1代码var $ name

<?php
 $hostname = "localhost";
$username = "xxx";
$dbname = "xxx";
$password = "xxx";
$usertable = "codes";
$yourfield = "code";
$connection = mysql_connect($hostname, $username, $password) OR DIE ("Unable to 
connect to database! Please try again later.");
mysql_select_db($dbname);



$query = "SELECT * FROM $usertable WHERE $yourfield = '" . $_GET["code"] . "' AND used = 0";
$result = mysql_query($query);
$rowSelected   = mysql_num_rows($result);
if ($rowSelected ) {
while($row = mysql_fetch_array($result)) {
        $name = $row["$yourfield"];
        $wert = $row["wert"];
        echo "Code valid<br>";
        echo "Code: $name<br>";
        echo "Value: $wert";
        $mysql_query($connection, 'UPDATE codes SET used=1 WHERE code="$name"');

    }


}
else {
echo "Code invalid!";
}
mysql_close($connect);
?>

1 个答案:

答案 0 :(得分:0)

中的引号错误
'UPDATE codes SET used=1 WHERE code="$name"'

他们应该

"UPDATE codes SET used=1 WHERE code='$name'"