First create a query page:
Copy the code The code is as follows:
Add record
You should still remember that in the previous topic, we have introduced how to transfer values between PHP pages technology. Similarly, in this page, when we click submit, we will pass the two parameters ename and pcname to the add_finish.php page through the post method.
Next is the most important thing, let’s take a look at how to write statements to add MySQL data in PHP:
Copy the code The code is as follows:
$link =mysql_connect("localhost" ,"root","Administrator password");
mysql_select_db("infosystem", $link);
$exec="insert into info (ename,pcname) values ('".$_POST["ename"]." ','".$_POST["pcname"]."')";
mysql_query("SET NAMES GB2312");
mysql_query($exec, $link);
mysql_close($link);
echo "Added successfully ! ";
?>
The red part is the key SQL statement for adding MySQL data to PHP. Then use mysql_query to execute this SQL statement.
I would like to remind everyone that you must pay attention to any symbol in the program, because this program has been tested by me and passed normally. When copying, you only need to copy everything, but when you write it yourself, you must pay attention to every symbol. A detail.
Another point is that everyone should make slight modifications to the program according to their own database structure to meet everyone's specific needs.
Today’s topic is relatively simple and briefly introduces how to add MySQL data records using PHP. I will add a more detailed introduction in a future topic.
The above introduces my life would suck without you PHP to add MySQL data recording code, including the content of my life would suck without you. I hope it will be helpful to friends who are interested in PHP tutorials.