Prepared Statements mySQLi

New records created successfully

Here is the code for accessing the database and display the information.

<?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);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $firstname, $lastname, $email);

// set parameters and execute
$firstname = "Tom";
$lastname = "Cat";
$email = "tc@example.com";
$stmt->execute();

$firstname = "Woody";
$lastname = "Woodpecker";
$email = "woody@example.com";
$stmt->execute();

$firstname = "Mighty";
$lastname = "Mouse";
$email = "mighty@example.com";
$stmt->execute();

echo "New records created successfully";

$stmt->close();
$conn->close();
?>