码迷,mamicode.com
首页 > 数据库 > 详细

表单内容插入数据库

时间:2016-04-08 20:16:08      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:ajax 表单 将数据插入数据库

<?php
header("content-type:text/html;charset=utf-8");
/* $mysql_username="localhost"; // 连接数据库用户名
    $mysql_password=""; // 连接数据库密码*/
    $mysql_database="test"; // 数据库的名字
    
    // 连接到数据库
   $conn = mysql_connect(‘localhost‘,‘root‘,‘‘) or die("MYSQL_connect:".mysql_errno());
    mysql_select_db($mysql_database);
     $name=$_POST[‘name‘];
     $age=$_POST[‘age‘];
    $sql = "INSERT INTO `test2` VALUES (‘$name‘,‘$age‘)";
    $query = mysql_query($sql);
   if($query){
        echo ‘1‘;
    }else{
        echo ‘注册失败!‘;
        }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
    <form id="form1"  method="post" action="1.php">
     <p>
         姓名:
         
        <input type="text" name="name"/>
     </p>
     <p >
         年龄:
       <input type="text" name="age"/>
     </p>
     <input type="submit"  value="提交"/>
    </form>
    <div id="request-process-patent"></div>
</body>

</html>

表单内容插入数据库

标签:ajax 表单 将数据插入数据库

原文地址:http://warmdoll.blog.51cto.com/10881334/1761839

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!