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

1
  • 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... Commented Apr 5, 2012 at 22:57

2 Answers 2

2

Maybe you need to quote your $pass value:

"INSERT INTO " . $my_tableName . "(mycolumn, myothercolumn)
values ('myvariable', '" . $pass . "');" .
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.