Search code examples
phpmysqlsqlmysql-error-1064

Mysql query syntax failing


I've been trying to execute this mysql query in my php file however I think there may be a problem with it as I get an error whenever it reaches the code.

Here is the query:

"INSERT INTO " . $my_tableName . "(mycolumn, myothercolumn)
values ('myvariable', " . $pass . ");" .
"INSERT INTO " .  $my_othertableName . "(morecolumns) values ('morevalues');"

And here is the error:

SQLSTATE[42000]: Syntax error or access violation: 1064 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";i:1;s:978:"#0


Solution

  • Maybe you need to quote your $pass value:

    "INSERT INTO " . $my_tableName . "(mycolumn, myothercolumn)
    values ('myvariable', '" . $pass . "');" .