问题描述:

what is my mistake in this code.. whenever i try to update its saying, 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 '0=T , 1=H , 2=R , 3=M, banned='0' WHERE cid='6'' at line 1

$name = $_POST['name'];

foreach($name as $field => $value){

$list[] = $field.'='."".mysql_real_escape_string($value)."";

}

$field = implode(', ',$list);

mysql_query("UPDATE subcours SET ".$field.", banned='{$_POST['status']}' WHERE `cid`='{$eid}' ") OR DIE (mysql_error());

网友答案:

First, $field in the foreach loop appeared to be a number ($name is a numeric indexed array), which could not be the column name.

Second, you missed the single quote.

$list[] = $field."='".mysql_real_escape_string($value)."'";

Third, consider using PDO.

相关阅读:
Top