Welcome, Guest!!

Date: Sunday, December 16th 2018 - Time:

Login Sign Up
 
 

Inserting multiple records into database with PHP and MySQL (308 Views)

Topic Started By: goddy       Created: Saturday, November 18th 2017 - 7:48 AM

Post a Reply or Comment
Share this on:
1
1

There are many ways you can do this and few examples are given below:

Inserting multiple records into database example one:

 

$sqlAdd = "INSERT INTO contacts (firstname, lastname, email)

VALUES ('Godwin', 'Asu', '[email protected]');";

$sqlAdd .= "INSERT INTO contacts (firstname, lastname, email)

VALUES ('Mary', 'Ene', '[email protected]');";

$sqlAdd .= "INSERT INTO contacts (firstname, lastname, email)

VALUES ('Emeka', 'Ogbonna', '[email protected]')";



if (mysqli_multi_query($conn, $sql)) {

    echo "Records added successfully";

} else {

    echo "Error add records: " . $sql . "

" . mysqli_error($conn);

}

 

Inserting multiple records into database example two:

INSERT INTO contacts (firstname, lastname, email)
values('$firstname', '$lastname', '$email')
,('$firstname', '$lastname', '$email')
,('$firstname', '$lastname', '$email')

Need more examples or clarifications, drop your comments below.

 


×

Subscribe to get notifications when I create new topics by clicking the SUBSCRIBE button at the top of this page if you have not already subscribed. Thanks.



Report spam or abuse
Re: Inserting multiple records into database with PHP and MySQL     •     1 year ago goddy said:

If you are connecting your web forms to the code, just replace the names e.g. Godwin with your form variables. Something similar to example two. Let me know if you have any problems.



Report spam or abuse
   (Page 1 of 1)      Comments (1)
Post a Reply or Comment

Related Topic (s) in Programming section.

BOOST YOUR WEBSITE TRAFFIC WITH 10 MILLIONS ACTIVE NIGERIAN EMAIL ADDRESSES

Marketing is the lifeblood of any business. Without it, your business is dead on arrival. It does not matter if you have the ...[Read more]


How to drive up to 20,000 real human Nigerian traffic daily to site

Here comes a unique traffic software that can send you 20,000 & mo Real human traffic to your Site unlimited targeted traffic software. This is ...[Read more]


Write Your First Website Right From Your Smartphone

Write Your First Website Right From Your Smartphone

A lots of people complained about having no Computer/System to . Doesn't matter, you can start with your Android phone right from ...[Read more]


Report topic

Report Comment