PHP MySQL insert into a combination of detailed
Ysql INSERT into statement is often used in the actual application of the statement, so the relevant content or a lot of good grasp.
Inserting data into a database table
The INSERT into statement is used to add a new record to a database table.
Grammar
INSERT into table_name
VALUES (value1, value2,....)
You can also specify the columns in which you want to insert data:
INSERT into table_name (column1, Column2,...)
VALUES (value1, value2,....)
Note: SQL statements are insensitive to case. Insert into is the same as insert into.
A 1.insert statement can insert multiple sets of values at a time, with each set of values enclosed in a pair of parentheses, separated by commas, as follows:
INSERT INTO ' news ' (Title,body,time) VALUES (' Title 1 ', ' body 1 ', now ()), (' Title 2 ', ' body 2 ', now ());
The 2.Insert Select statement inserts the result of the query into a new table, as the name suggests, consisting of an Insert statement and a Select statement
Insert into News_one (id,title,body,time) select Id,title,body,time from News_two;
Note that the structure of the two tables is identical and the column names can be different.
How to use in PHP
The following is the code for the "insert.php" page:
<?php
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
$sql = "INSERT into Persons (FirstName, LastName, age)
VALUES
(' $_post[firstname] ', ' $_post[lastname] ', ' $_post [age] ');
if (!mysql_query ($sql, $con))
{
die (' Error: '. mysql_error ());
}
echo "1 record added";
Mysql_close ($con)
?>
Thank you for reading, I hope to help you, thank you for your support for this site!