21,887
社区成员
发帖
与我相关
我的任务
分享
<!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>
<div>
<form action="zhuce.php" method="post">
<table width="200" border="1">
<tr>
<td>用户名:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>性 别:</td>
<td><p>
<label>
<input type="radio" name="sex" value="boy" id="sex_0" />
男</label>
<label>
<input type="radio" name="sex" value="g" id="sex_1" />
女</label>
</p></td>
</tr>
<tr>
<td><input type="submit" name="button" id="button" value="提交" /></td>
<td><input type="reset" name="button2" id="button2" value="重置" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015/8/15
* Time: 16:28
*/
//连接服务器
define("mysql_host","localhost");
define("mysql_user","root");
define("mysql_pw","");
function connectdb(){
$conn=mysql_connect(mysql_host,mysql_user,mysql_pw);//连接MySQL服务器
if(!$conn){
die("服务器连接失败");
}
mysql_select_db("test",$conn);//选择test表单
return $conn;
}
?>
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015/8/16
* Time: 15:02
*/
if(!isset($_POST['name'])){
die('user name not define');
}
if(!isset($_POST['password'])){
die('user password not define');
}
if(!isset($_POST['sex'])){
die('user sex not define');
}
$name=$_POST['name'];
if(empty($name)){
die('user name not empty');
}
$password=$_POST['password'];
if(empty($password)){
die('user password not empty');
}
$sex=$_POST['sex'];
if(empty($sex)){
die('user sex not empty');
}
require_once 'connect_server.php';
connectDb();
mysql_query("insert into users(name,password,sex) VALUES ('$name','$password','$sex')");
header("location:index.php");