当前位置:编程学习 > php >>

php 插入数据,insert 保存记录

php 插入数据,insert 保存记录,我们入门的朋友经常会看到吧,用mysql insert into进行数据的保存

<?php
if($_POST[ok])
{
 $link_id = mysql_connect("localhost","root","") or die("连接失败");
 if($link_id)
 {
  //选择数据库
  mysql_select_db("my_test");
  //插入数据SQL语句
  $sql="insert into userinfo values('".$_POST[id]."','".$_POST[name]."','".$_POST[gender]."','".$_POST[age]."','".$_POST[regdate]."')";
  //执行SQL语句
  $result=mysql_query($sql);
  if($result)
  {
   echo "记录已经成功插入<br><a href='insert.php'>继续插入记录</a>";
  }
  else
   echo "执行插入SQL语句失败";
  //关闭数据库
  mysql_close($link_id);
 }
}
else
{
 ?>
 <form method=post action=insert.php>
 编号<input type=text name="id"><br>
 姓名<input type=text name="name"><br>
 性别<input type=text name="gender" ><br>
 年龄<input type=text name="age"><br>
 注册时间<input type=text name="regdate"><br>
         
 <input type=submit name=ok value="提交">
 </form>
 <?
}//end if
?>

补充:Php教程,Php入门 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,