0

The error message I'm getting:

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 'INSERT INTO accounts(balance, interest) VALUES(0, 1.5)' at line 4 in INSERT INTO accounts(id_user, interest) VALUES(73, 'Savings'); INSERT INTO balance(balance, interest) VALUES(0, 1.5)

My PHP code is:

$query = "INSERT INTO accounts(`id_user`, `type`)
          VALUES($userid, '$type');

          INSERT INTO balance(`balance`, `interest`)
          VALUES(0, $interest)";

My first guess that something was wrong with my query, so I tried to run the exact same query in phpMyAdmin and it worked perfectly.

Any suggestions on what might be wrong ?

2
  • 2
    You are probably using an interface function that only allows a single statement rather than a compound statement. Commented Dec 1, 2015 at 23:08
  • I'm using the mysql_query() Commented Dec 1, 2015 at 23:20

2 Answers 2

2

Gordon Linoff is correct.

From the great manual in the sky.

"mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier. "

http://php.net/manual/en/function.mysql-query.php

change

$query = "INSERT INTO accounts(`id_user`, `type`)
          VALUES($userid, '$type');

          INSERT INTO balance(`balance`, `interest`)
          VALUES(0, $interest)";

to

$query = "INSERT INTO accounts(`id_user`, `type`)
          VALUES($userid, '$type');";
result = mysql_query($query);

$query="INSERT INTO balance(`balance`, `interest`)
          VALUES(0, $interest)";
result = mysql_query($query);
Sign up to request clarification or add additional context in comments.

Comments

2

Are you using mysqli to run this ? I suspect you are running two queries in a single statement, you need to use mysqli_multi_query function to execute multiple queries at the same time.

Mysqli Manual page on multi_query

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.