问题描述:

I'm having a hard time finding the error that exists in my script. Can anyone help me spot it?

 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--;

}

}

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order='55' WHERE video_id='video55'' at line 1

Thanks!

网友答案:

order is a reserved keyword in MySQL. You must specify the column name instead. Put backticks around "order".

相关阅读:
Top