Saturday 5 November 2016

SQL syntax error while update sql with php



I have a problem, i try to update a mysql database with my php script but i become the message:




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 'mod = 3, drehtage = 4, schnitttage = 5, dreh = 0, schnitt = 0, off = 0, leiter =' at line 1


i hope you can help me, here is my code to update the database (i just edit the user + pass ;) )





$con = mysql_connect('localhost', 'user', 'pass');
if (!$con)
{

die('Could not connect: ' . mysql_error());
}

mysql_select_db("kup_projekte", $con);

$aendern = "UPDATE drehs SET name = '".$t1."', drehdatum = '".$t2."', schnittdatum = '".$t3."', kamera = '".$t4."', assi = '".$t5."', mod = '".$t6."', drehtage = '".$t7."', schnitttage = '".$t8."', dreh = '".$t9."', schnitt = '".$t10."', off = '".$t11."', leiter = '".$t12."' Where id = '".$id."'";

$update=mysql_query($aendern);
mysql_close($con);




// EDIT //



the variables $t1 - $t12 are filled and comes correctly.


Answer



mod is a mysql reserved word. If you want to use it as a column name, you must enclose it in backticks (`) in your SQL queries


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...