php-mysqlInserting data to MySQL using PHP
Inserting data to MySQL using PHP is a common task for web developers. It can be done using the mysqli_query() function. The following example code inserts a new record into a table called users:
$sql = "INSERT INTO users (name, email) VALUES ('John Doe', '[email protected]')";
mysqli_query($conn, $sql);
The code above will insert a new record with the name John Doe and email [email protected] into the users table.
The code consists of two parts:
- The SQL query: 
$sql = "INSERT INTO users (name, email) VALUES ('John Doe', '[email protected]')";- This part of the code defines the SQL query that will be used to insert the data.
 
 - The 
mysqli_query()function:mysqli_query($conn, $sql);- This part of the code executes the SQL query and inserts the data into the database.
 
 
Helpful links
More of Php Mysql
- How to get the version of MySQL using PHP?
 - How to use a variable in a MySQL query using PHP?
 - How to use a MySQL union in PHP?
 - How to set a timeout for MySQL query in PHP?
 - How to call a stored procedure in MySQL using PHP?
 - How to run multiple queries in PHP and MySQL?
 - How to list databases in PHP and MySQL?
 - How to check the result of an insert in PHP and MySQL?
 - How to insert a date into a MySQL database using PHP?
 - How to check if a record exists in PHP and MySQL?
 
See more codes...