PHP - SQL查询语法错误

时间:2010-10-10 18:01:24

标签: php sql

我很难找到脚本中存在的错误。谁能帮我发现它?

        case "process_movie_order":
        // handle POST
        if ($_POST) {
            //Drop "order" column and Re-ADD it to reset ID #'s
            $droppedresult = mysql_query("ALTER TABLE videos DROP COLUMN order");
            $addedresult = mysql_query("ALTER TABLE videos ADD order int NOT NULL");
            $totalMovies = count($_POST['movie']);
            // use $i to increment the order number
            $i=$totalMovies;
            // loop through post array in the order it was submitted
            foreach ($_POST['movie'] as $video_id) {
                // update the row                    
                $query = sprintf("UPDATE videos SET order='%s' WHERE video_id='%s'",
                    mysql_real_escape_string($i),
                    mysql_real_escape_string($video_id));

                $result = mysql_query($query);

                 if(!$result) {
                     echo mysql_error();
                    echo 'MySQL query failed. Please report this error to the author of this script.<br />
                        <br />
                        <a href="'.$script_location.'?action=show_landing_page">Back</a><br />';
                    break;
                }             
                // decrease order number to make the next movie lower
                $i--;
            }
        }

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在第1行'order ='55'WHERE video_id ='video55''附近使用正确的语法

谢谢!

1 个答案:

答案 0 :(得分:2)

order是MySQL中的保留关键字。您必须改为指定列名称。在“订单”周围加上反击。