Add data to the MySQL database. PHP function example open

Add data to the MySQL database. PHP function example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: PHP 5.6 +

The INSERT command is used to add data to MySQL:

INSERT INTO table_name (column1, column2, column3) VALUES ( value1, value2, value3)

Add data to the database function example:

$conn = mysqli_connect("localhost", "root", "password", "testdb");

if (!$conn) {
  die("Error: " . mysqli_connect_error());
}

$sql = "INSERT INTO Users (name, surname, age) VALUES ('Stiven', 'Sigal' 57)";

if(mysqli_query($conn, $sql)){
    echo "User added";
} else{
    echo "Error: " . mysqli_error($conn);
}

mysqli_close($conn);
?>
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation