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

GROUP BY Clause and HAVING Clause in PHP

Method Overriding in Traits in PHP

Mysqli database Connection and Display Table Data from Database