To embed information into MySQLi table, you would have to utilize SQL INSERT INTO order. You can embed information into MySQLi table by utilizing mysql> brief or by utilizing any content like PHP.
Syntax
Here is conventional SQL linguistic structure of INSERT INTO order to embed information into MySQLi table:
INSERT INTO table_name
( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
To embed string information types, it is needed to keep all the qualities into twofold or single statement, for instance:- "esteem".
Inserting Data from Command Prompt
This will utilize SQL INSERT INTO order to embed information into MySQLi table tutorials_inf.
Example
Following model will make 3 records into tutorials_tbl table −
root@host# mysql -u root -p password;
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> INSERT INTO tutorials_inf
->(id, name)
->VALUES
->(10, "John Poul");
Query OK, 1 row affected (0.01 sec)
NOTE − Please note that all the bolt signs (- >) are not piece of SQL order; they are demonstrating another line and they are made consequently by MySQL brief while squeezing enter key without giving a semicolon toward the finish of each line of the order.
Inserting Data Using PHP Script
You can utilize same SQL INSERT INTO order into PHP work mysqli_query() to embed information into a MySQLi table.
Example
This model will take three boundaries from client and will embed them into MySQLi table −
<html>
<head>
<title>Add New Record in MySQLi Database</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
</head>
<body>
<div id = "main">
<form action = "" method = "post">
<label>Name :</label>
<input type = "text" name = "name" id = "name" />
<br />
<br />
<input type = "submit" value ="Submit" name = "submit"/>
<br />
</form>
</div>
<?php
if(isset($_POST["submit"])){
$servername = "localhost:3306";
$username = "root";
$password = "<Password here>";
$dbname = "TUTORIALS";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO tutorials_inf(name)VALUES ('".$_POST["name"]."')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "" . mysqli_error($conn);
}
$conn->close();
}
?>
</body>
</html>
The example yield ought to be this way −
New record created successfully