Inserting a record or data into mysql database tables is very easy task.
We can use mysqli_query function to execute the query to add a record in table.
Example with code and syntax :
// connect to mysql database using userid and password
if (mysqli_connect_errno())
{
echo "Error while connecting to MySQL: " . mysqli_connect_error();
}
//***********Connection Successful to emp_db database in mysql************
// Now you can add a record in mysql database
We can use mysqli_query function to execute the query to add a record in table.
Example with code and syntax :
<?php
$mysqlcon=mysqli_connect("localhost","uid","password","emp_db");
$mysqlcon=mysqli_connect("localhost","uid","password","emp_db");
// connect to mysql database using userid and password
if (mysqli_connect_errno())
{
echo "Error while connecting to MySQL: " . mysqli_connect_error();
}
//***********Connection Successful to emp_db database in mysql************
// Now you can add a record in mysql database
mysqli_query($mysqlcon,"INSERT INTO emp_db(empname,empid)
VALUES ('sagar', 234343)");
mysqli_close($mysqlcon);
VALUES ('sagar', 234343)");
mysqli_close($mysqlcon);
//close the connection from mysql database
?>
If there is any error while running above script, we are printing that as well.
No comments:
Post a Comment