获取表格数据,添加数据库记录
首先创建个带有简单表格的html网页
<form action="five.php" method="post">
id <input type="text" name="id" /> first <input type="text" name="first" /> last <input type="text" name="last"/> <input type="submit" /> 其次再创建php文件,获取到表格输入的内容,并把它们发送给数据库。
<?php
$db=mysql_connect("localhost","root","123456"); mysql_select_db("mydb",$db); if(!$db) { echo "fail"; //('Could not connect: ' . mysql_error()); } $sql="insert into employees(id,first,last) values('$_POST[id]','$_POST[first]','$_POST[last]')"; /*if(!mysql_query($sql,$db)) { die('error:',mysql_error()); }*/ mysql_query($sql); echo $sql; //echo "1 record added"; mysql_close($db); ?> 这样数据库的记录就添加成功了! 本文出自 51CTO.COM技术博客 |


AimeeLife
博客统计信息
热门文章
最新评论
友情链接