Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Created December 27, 2020 21:39
Show Gist options
  • Save barmgeat/8470eb525781ca0d9c219619630e2d7e to your computer and use it in GitHub Desktop.
Save barmgeat/8470eb525781ca0d9c219619630e2d7e to your computer and use it in GitHub Desktop.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//create string statement .
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]');";
//here we concatent the data to insert to the database :
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Mary', 'Moe', '[email protected]');";
//here we concatent the data to insert to the database :
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Julie', 'Dooley', '[email protected]')";
//then we use multi_query function to insert the data to the Table MyGuestes
if ($conn->multi_query($sql) === TRUE) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment