In this section, we will figure out how to embed information in a table.
Embeddings information into a table requires the INSERT order. The overall sentence structure of the order is INSERT trailed by the table name, fields, and qualities.
Audit its overall punctuation given beneath −
INSERT INTO tablename (field,field2,...) VALUES (value, value2,...);
The assertion requires the utilization of single or twofold statements for string esteems. Different alternatives for the assertion incorporate "INSERT...SET" proclamations, "INSERT...SELECT" explanations, and a few different choices.
Note − The VALUES() work that shows up inside the proclamation, possibly applies to INSERT articulations and returns NULL whenever utilized somewhere else.
Two alternatives exist for playing out the activity: utilize the order line or utilize a PHP content.
The Command Prompt
At the brief, there are numerous approaches to play out a select activity. A standard assertion is given underneath −
belowmysql>
INSERT INTO products_tbl (ID_number, Nomenclature) VALUES (12345,“Orbitron 4000”);
mysql> SHOW COLUMNS FROM products_tbl;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| ID_number | int(5) | | | | |
| Nomenclature| char(13) | | | | |
+-------------+-------------+------+-----+---------+-------+
You can embed various columns −
INSERT INTO products VALUES (1, “first row”), (2, “second row”);
You can likewise utilize the SET statement −
INSERT INTO products SELECT * FROM inventory WHERE status = 'available';
PHP Insertion Script
Utilize the equivalent "Supplement INTO..." proclamation inside a PHP capacity to play out the activity. You will utilize the mysql_query() work by and by.
Audit the model given underneath −
<?php
if(isset($_POST['add'])) {
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() ) {
$product_name = addslashes ($_POST['product_name']);
$product_manufacturer = addslashes ($_POST['product_name']);
} else {
$product_name = $_POST['product_name'];
$product_manufacturer = $_POST['product_manufacturer'];
}
$ship_date = $_POST['ship_date'];
$sql = "INSERT INTO products_tbl ".
"(product_name,product_manufacturer, ship_date) ".
"VALUES"."('$product_name','$product_manufacturer','$ship_date')";
mysql_select_db('PRODUCTS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
?>
On effective information inclusion, you will see the accompanying yield −
mysql> Entered data successfully
You will likewise work together approval articulations with embed explanations, for example, checking to guarantee right information passage. MariaDB incorporates various choices for this reason, some of which are programmed.