SQL INSERT INTO Statement
INSERT INTO statement Syntax and Usage.
There are two basic way syntaxes of the INSERT INTO statement.
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
StudentID | StudentName | ParentsContact | Address | Country | DOB | Section |
Branch |
1 |
Liam | 10101010 | 23 MG road Banglore |
INDIA | 12/06 | A | CSE |
2 | Andrew | 20202020 | 2415 Anthony market str | Germany | 01/02 | A | ISE |
3 | Joshua | 30303030 | 26547 David church road | USA | 18/04 | B | CL |
4 | Ryan | 40404040 | 18 Krishna sq. Banglore |
INDIA | 26/12 | B | EE |
5 | Charles | 50505050 | 878 Eli Berguvsvägen 8 | INDIA | 23/11 | C | ECE |
INSERT INTO Example(one way).
SQL statement inserts a new record in the "student" table using column names .
INSERT INTO Student (StudentName, ParentsContact,Address, Country, DOB,Section,Branch)
VALUES ('leo', '12345678', 'Skagen 21', 'USA','15/12','C','ME');
INSERT INTO Student VALUES ('Jack', '12345688', 'washington 21', 'USA','12/02','D','ME' );
<!DOCTYPE html>
<html lang="en">
<head>
<title>How to use SQL INSERT INTO Statement</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<br>
<br>
<br>
<div class="text-center">
<h1>How to use SQL INSERT INTO Statement</h1>
</div>
<div class="well">
<?php
$connect = mysqli_connect("localhost", "root", "", "school_management");
if($connect === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "INSERT INTO Student (StudentName, ParentsContact,Address, Country, DOB,Section,Branch)
VALUES ('leo', '12345678', 'Skagen 21', 'USA','15/12','C','ME')";
if(mysqli_query($connect, $sql)){
echo "New Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect);
}
mysqli_close($connect);
?>
</div>
<br>
</div>
</body>
</html>