Home Ask Login Register

Developers Planet

Your answer is one click away!

Some One February 2016

How do you pass multiple sql statements using php

This is what i want to do but with lots of records. When i try this i get this kind of error:the error message i get

this is my currant php and when i submit it no record is added.

$sql = "INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) VALUES (NULL, 'firstnameA', 'surnameA', 'example1@email.com', CURRENT_TIMESTAMP);
    INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) VALUES (NULL, 'firstnameB', 'surnameB', 'example@email.com', CURRENT_TIMESTAMP);
    " ;

However this code works but i am only adding one record

$sql = "INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) VALUES (NULL, 'tom', 'walker', 'tom@walker.com', CURRENT_TIMESTAMP);


WheatBeak February 2016

Use mysqli_multi_query check out:


aynber February 2016

You just need to duplicate the values portion, like this:

$sql = "INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) 
   VALUES (NULL, 'tom', 'walker', 'tom@walker.com', CURRENT_TIMESTAMP), 
   (NULL, 'bob', 'jones', 'bob@jones', CURRENT_TIMESTAMP)";

Post Status

Asked in February 2016
Viewed 1,856 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life