MySQL - 无法更新多个列

时间:2012-09-23 14:23:14

标签: php mysql sql database

每当我尝试从PHP更新选定行中的列时,它都会顺利通过,但不会在数据库中更新。

$query = "UPDATE news SET title = '$title', 
                  cover = '$cover', desc = '$newz', category = '$category' 
        WHERE id = $newz_select_id";

1 个答案:

答案 0 :(得分:4)

desc reserved keyword in MySQL 。用反引号(`)代替它。

$query = "UPDATE news SET title = '$title', 
              cover = '$cover', `desc` = '$newz', category = '$category' 
    WHERE id = $newz_select_id";
顺便说一句,你的代码很容易被sql注入。为了避免它,请学习并使用PHP PDO或PHP mySQLi Extensions。

See this Link: Best way to prevent SQL Injection