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', '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);
"
Some One
  • 1
  • 2

2 Answers2

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', 'tom@walker.com', CURRENT_TIMESTAMP), 
   (NULL, 'bob', 'jones', 'bob@jones', CURRENT_TIMESTAMP)";
aynber
  • 22,380
  • 8
  • 50
  • 63
0

Use mysqli_multi_query check out:

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

WheatBeak
  • 1,036
  • 6
  • 12