First create a query page:
Copy code The code is as follows:
Add record
You should still remember that the technology of how to transfer values between PHP pages has been introduced in the previous topic. 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 use PHP to write statements to add MySQL data:
Copy code The code is as follows :
$link =mysql_connect("localhost","root","admin 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 Be sure to pay attention to every detail.
Another point is that everyone should make subtle 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 use PHP to add MySQL data records. I will add a more detailed introduction in a future topic.
http://www.bkjia.com/PHPjc/319146.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319146.htmlTechArticleFirst create a query page: Copy the code as follows: html head /head body h3Add record/h3 formaction="add_finish .php"method="POST" Employee name: inputtype="text"size=25name="en...