Insert multiple records into MySQL with a single query

lapo78 09 Dec, 2011
Hi, Can I Insert multiple records into MySQL with a single query?
Thanks
GreyHead 09 Dec, 2011
Hi Lapo,

Yes, you can. See the INSERT . . . SET . . . VALUES . . . syntax in the MySQL manual for the way to write the query

Bob
lapo78 10 Dec, 2011
Thanks, Can I enter the query using php by submit? If yes, i use the "Custom Code" OnSubmit? Thanks
GreyHead 10 Dec, 2011
Hi Lapo,

Yes you can.

Bob
lapo78 10 Dec, 2011
SOLVED!!!
<?php
$input_1 = $form->data['input_1'];
$other_input_1 = $form->data['other_input_1'];
$input_2 = $form->data['input_2'];
$other_input_2 = $form->data['other_input_2'];
$db =& JFactory::getDBO();
$query = "INSERT INTO table_name (field_a, field_b) VALUES ('$input_1','$other_input_1'),('$input_2','$other_input_2');";

$db->setQuery($query);
$db->query();
$id = $db->insertid();

?>
This topic is locked and no more replies can be posted.