Insert Multiple Records in Mysqli Database

 <?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "heer";

//  Create Connection
$conn = new mysqli($servername, $username, $password, $dbname);

//  Check Connection
if($conn->connect_error)
{
    die("Connection Failed:" . $conn->connect_error);
}
echo "Connection Successfully" . "<br>";

// $sql = 'INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(3, "Chirag", 44, "Male", "9855632210", "Mumbai")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(4, "Aadit", 29, "Male", "8544632217", "Pune")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(7, "Manish", 33, "Male", "5499632207", "Mumbai")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(8, "Nishant", 20, "Male", "8233012278", "Delhi")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(10, "Kunj", 22, "Male", "7455210036", "Delhi")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(11, "Priyanshi", 33, "Female", "9522473321", "Pune")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(13, "Urvashi", 24, "Female", "9233048854", "Mumbai")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(14, "Prachi", 55, "Female", "9355478801", "Chennai")';
// $sql .= ';INSERT INTO student(id, name, age, gender, phone, city)
//         VALUES(17, "Hirva", 10, "Female", "8522301167", "Chennai")';

if($conn->multi_query($sql) === TRUE)
{
    echo "New Data inserted Successfully" . "<br>";
} else {
    echo "Error: " . $sql . "<br>" . $conn_error;
}
$conn->close();

?>

Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

Displaying Database data using Class, Object, Constructor, Destructor in PHP MySql

SubQuery with EXISTS and NOT EXISTS in PHP