$ _POST变量与MySQL结合使用会产生MySQL语法错误 - 第1行附近的“1”[关闭]

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 '' at line 1

The query works but the error report "bugs" me :)

//the vars i use
$pos = $_POST['positie'];   //this can be B1 till M100
$kolom = $pos[0];           //get first char of the $pos string 
$rij = substr($pos, 1, 3);  //get the rest of the chars

$sql= mysql_query("UPDATE floorplan SET available='0' WHERE kolom='$kolom' AND rij='$rij'") or die( mysql_error() );

the kolom is varchar(4), rij is int(4) and avaiable is a BOOLEAN.

In mysql, boolean is simply synonym for TINYINT(1). A value of 0 is considered FALSE. So, change

$rij = substr($pos, 1, 3);

to

$rij = intval(substr($pos, 1, 3));

and query to

"UPDATE floorplan SET available=0 WHERE kolom='$kolom' AND rij=$rij"

would solve your problem but like others said, you should think about SQL Injection.

Suppose $pos has a value of "B1".

Then, substr($pos, 1, 3); will return an out of bounds exception.

Try with substr($pos, 1);