1

I am trying to do multiple insertions using mysqli_multi_query() and following is my code. The issue is its not executing the result . Kindly let me know what i did wrong?

$query = "INSERT INTO crap_table (name, number, class)VALUES ('Peter', 35,'BS')";
$query .= "INSERT INTO crap_table (name, number, class)VALUES ('Sahil', 35,'MS')";
mysqli_multi_query($con,$query);

2 Answers 2

3

mysqli_multi_query

Executes one or multiple queries which are concatenated by a semicolon.

You need to have a ; between them. Like

$query = "INSERT INTO crap_table (name, number, class)VALUES ('Peter', 35,'BS');";
                                                                               ^
$query .= "INSERT INTO crap_table (name, number, class)VALUES ('Sahil', 35,'MS')";

Provided that you are connected to the database already? Like

$con= mysqli_connect("localhost", "my_user", "my_password", "world");
Sign up to request clarification or add additional context in comments.

2 Comments

Please select this answer as the approved answer if this is the answer you needed. It's the little checkmark under the vote number.
@DenizZoeteman I would have selected it earlier but due to 8 mins constraint i could not
1
$query = "INSERT INTO crap_table (name, number, class)VALUES ('Peter', 35,'BS');";
$query .= "INSERT INTO crap_table (name, number, class)VALUES ('Sahil', 35,'MS')";
mysqli_multi_query($con,$query);

You forgot ; between your queries.

Executes one or multiple queries which are concatenated by a semicolon.

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.