How to insert data into database in mysql with php?

Sql Insert query is used to insert data into database.

Insert into table_name(column_name1, column_name2) values(value1, value2);

Example

<?php
// connect with db
$con = mysqli_connect('localhost', 'root', '', 'myDB');
if(!$con) {
   die('Connection not established.');
}
// write a query
$sql = "Insert into table_name(column_name1, column_name2) values(value1, value2)";
$query = mysqli_query($con, $sql);
if($query) {
   echo '<p>Data inserted.</p>';
}
else {
   // show error why not data inserted
   echo '<p>Data not inserted.</p>'.mysqli_error($con);
}
?>

kabeer

Added  Jul 03, 01:15 am

×
Google login
SignUp with Email
X