Inserting data to the table using php
Once the table is created, the next job is to insert data into the table. For this ,we use the INSERT INTO command. The program below describes how to insert data to the table in the database.
Output:
The num:1 and user:jino that we entered are stored in the table in the database. You can see how to view the entered data from the database directly in the next page.
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="mydb";
//connecting...
$conn=new mysqli($servername,$username,$password,$dbname);
//checking...
if($conn->connect_error)
{
die("connection failed:".$conn->connect_error);
}
//inserting into the table
$sql="INSERT INTO firsttable VALUES(1,'jino');";
if($conn->query($sql)===TRUE)
{
$last_id=$conn->insert_id;
echo "new record inserted sucessfully created<br>last inserted row is:".$last_id;
}
else
{
echo "error :".$conn->error;
}
$conn->close();
?>
Output:
new record inserted sucessfully
The num:1 and user:jino that we entered are stored in the table in the database. You can see how to view the entered data from the database directly in the next page.
⇐Prev
Next⇒
Comments
Post a Comment