Mysql更新错误

时间:2011-04-08 17:29:10

标签: mysql

我收到此错误: 'where子句'中的未知列'richard' 在这段代码中:

if(isset($_POST['Zabanovat'])){;
    $nick = $_POST['nick'];
    $ban = $_POST['ban'];
    mysql_query("UPDATE TABLE Set usr_unban = $ban   WHERE usr_nick =  $nick    ") OR die(mysql_error());
}

echo "<form method=\"post\">";

echo "<div class=\"formatLabel\"><label for=\"nick\"><h2>Zadejte jméno banovaného účtu</h2></label></div>";
echo "<div class=\"formatContent\"><input type=\"text\" id=\"nick\" name=\"nick\"></div>";

    echo "<div class=\"formatLabel\"><label for=\"ban\"><h2>Zadejte datum unbanu (dd.mm.yyyy)</h2></label></div>";
echo "<div class=\"formatContent\"><input type=\"text\" id=\"ban\" name=\"ban\"></div>";

echo "<div class=\"formatSubmit\"><input type=\"submit\" value=\"Zabanovat\" name=\"Zabanovat\"></div>";

echo "</form>";

2 个答案:

答案 0 :(得分:0)

我认为在输入查询时缺少表名,除非您的表名为“TABLE”:

mysql_query("UPDATE TABLE Set usr_unban = $ban WHERE usr_nick = $nick ") OR die(mysql_error()); }

应该是:

mysql_query("UPDATE **TABLE_NAME** Set usr_unban = $ban WHERE usr_nick = $nick ") OR die(mysql_error()); }

请记住,SQL中的UPDATE clase是:

UPDATE "table_name"
SET "column_1" = [new value]
WHERE {condition}

答案 1 :(得分:0)

如果变量不包含数值,则必须将变量放在单引号中。

mysql_query("UPDATE TABLE Set usr_unban = '$ban' WHERE usr_nick = '$nick'") OR die(mysql_error());