在php端根据$_POST['name']方式获取到对应的表单内容,然后在通过insert方式添加到数据库就可以了啊。。
参考这里:http://www.w3school.com.cn/php/php_mysql_insert.asp
以下是代码:
1
2
3
4
5
6
7
HTML:
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
$con = <a href="https://www.baidu.com/s?wd=mysql_connect&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4P1PWrjRvuH-WnHf3myFW0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdPHn1rjb4nWb3rjfLrjckP1c" target="_blank" class="baidu-highlight">mysql_connect</a>("localhost","peter","abc123")//连接数据库
if (!$con){
die('Could not connect: ' . mysql_error())
}
<a href="https://www.baidu.com/s?wd=mysql_select_db&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4P1PWrjRvuH-WnHf3myFW0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdPHn1rjb4nWb3rjfLrjckP1c" target="_blank" class="baidu-highlight">mysql_select_db</a>("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)
?>
html代码:input.html
<form action="handle.php" method="post">
这里代码省略,就是你要输入的内容的表单
</form>
PHP代码如下:
handle.php页面如下:
<?php
$link=mysql_connect("localhost","dugucloud","12345678")
mysql_select_db("dugudata",$link)
mysql_query("set names utf8")
$name=$_POST['name']
$sex=$_POST['sex']
$sql="insert into dutable (name,sex) values ('".$name."','".$sex."')"
mysql_query($sql)
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)