0

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', '[email protected]', CURRENT_TIMESTAMP);
    INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) VALUES (NULL, 'firstnameB', 'surnameB', '[email protected]', 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', '[email protected]', CURRENT_TIMESTAMP);
"
2

2 Answers 2

1

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

$sql = "INSERT INTO `people` (`id`, `firstname`, `lastname`, `email`, `reg_date`) 
   VALUES (NULL, 'tom', 'walker', '[email protected]', CURRENT_TIMESTAMP), 
   (NULL, 'bob', 'jones', 'bob@jones', CURRENT_TIMESTAMP)";
Sign up to request clarification or add additional context in comments.

2 Comments

remember the semicolon after the closing quote marks
Good point. Moved it, since it doesn't need to be inside.
0

Use mysqli_multi_query check out:

http://php.net/manual/en/mysqli.multi-query.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.