php sql insert
snippet in php

php sql insert

user1320


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


 
$sql = "INSERT INTO MyGuests (firstname, lastname, email)

 VALUES ('John', 'Doe', 'john@example.com')";

 
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>
 

insert php code

user2785

<?php
$host = "localhost";
$username = "username";
$pass = "";
$db="furniture";


// Create connection
$conn=mysqli_connect($host,$username,$pass,$db);

if(!$conn){
  die("Data connection error");
}
?>