1

When I execute:

mysql_query("SELECT * FROM people WHERE fname = '$fname'; INSERT INTO people (first_name) VALUES ('$fname')") or die(mysql_error());

I receive this error:

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 people (first_name) VALUES ('Draski')' at line 1

Where is the syntax error?

1
  • 1
    You can only run one query with mysql_query(), not multiple. So, make it different function calls. Also, mysql_ is deprecated, for new code, please use mysqli_ or PDO. Commented Dec 18, 2013 at 2:01

2 Answers 2

2

You can't do run two queries in one statement with the mysql_* API. You will have to run them in two separate queries.

You can do it with mysqli_*, however. And since the mysql_* API is deprecated you should be using an alternative API like mysqli_* anyway.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it worked. Will select as answer when I can.
0

Use this function mysqli_multi_query for multiple queries.

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.