This article mainly shares with you how to insert data into the database table in PHP. It is mainly shared with you in the form of code. I hope it can help you.
php insert data page insertData.php
<html> <head> <title>向数据库中插入数据</title> </head> <body> <center> <form name="myForm" method="post" action="processInsertData.php"> <table bgcolor="cyan"> <tr> <td>学号</td> <td><input type="text" name="txtId" /></td> </tr> <tr> <td>姓名</td> <td><input type="text" name="txtName" /></td> </tr> <tr> <td>年龄</td> <td><input type="text" name="txtAge"></td> </tr> <tr> <td>性别</td> <td> <select name="sSex"> <option value="male">male</option> <option value="female">female</option> </select> </td> </tr> <tr> <td>地址</td> <td><input type="text" name="txtAddress"/></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="添加"/> <input type="reset" name="reset" value="重置"> </td> </tr> </table> </form> </center> </body> </html>
Process data insertion page processInsertData.php
<?php $link=mysql_connect("localhost","root","root"); mysql_select_db("rorely"); $id=$_POST['txtId']|null; $name=$_POST['txtName']; $age=$_POST['txtAge']; $sex=$_POST['sSex']; $address=$_POST['txtAddress']; $exec="insert into test values($id,'$name',$age,'$sex','$address')"; $result=mysql_query($exec); if($result) echo "学生已添加到数据表中<br>"; else echo "该学生没有添加进数据表,请重新输入。<br>"; mysql_close(); ?> <a href="insertData.php">返回添加页面</a>
Related recommendations:
Detailed explanation of the simple extension class of Yii framework batch insert data
Introduction to how to optimize MYSQL batch insert data
The above is the detailed content of PHP implements inserting data into database table. For more information, please follow other related articles on the PHP Chinese website!