Home  >  Article  >  php教程  >  php 保存数据到mysql数据库实例

php 保存数据到mysql数据库实例

WBOY
WBOYOriginal
2016-06-08 17:30:051060browse

保存用户提交的数据到mysql数据库是WEB 开发者必须掌握的基础知识了,下面我们就来讲一下是怎么把用户提交的数据保存到数据库的吧。

<script>ec(2);</script>

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 "记录已经成功插入
继续插入记录";
  }
  else
   echo "执行插入SQL语句失败";
  //关闭数据库
  mysql_close($link_id);
 }
}
else
{
 ?>
 


 编号

 姓名

 性别

 年龄

 注册时间

         
 
 

 
}//end if
?>
转载注明www.111cn.net/phper/php.html
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn