Mysql query syntax failing

Go To StackoverFlow.com

1

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

2012-04-05 22:52
by Sam Jackson
It seems you are trying to execute two sql statement on one line hence the "." between the queries. Secondly put a space after the quote joining the fields - $my_tableName . " (mycolumn.. - Chibuzo 2012-04-05 22:57


2

Maybe you need to quote your $pass value:

"INSERT INTO " . $my_tableName . "(mycolumn, myothercolumn)
values ('myvariable', '" . $pass . "');" .
2012-04-05 22:55
by barsju


1

In PHP you can't execute multiple insert statements separated with a ;. You need to execute these as separate queries. This is to prevent injection. Try running as 2 queries and it should work fine for you.

2012-04-05 22:57
by DaOgre
Ads