Add data to the MySQL database. PHP OOP code example open

Add data to the MySQL database. PHP OOP code example

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

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 OOP PHP example:


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

if($conn->connect_error){
    die("Error: " . $conn->connect_error);
}

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

if($conn->query($sql)){
    echo "User added";
} else{
    echo "User not added" . $conn->error;
}

$conn->close();
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