<?php
	session_start();
	include "conn/conn.php";
	header('content-type:text/html; charset=gb2312');
	$name = $_POST['name'];
	$password1 = $_POST['password1'];
	$password2 = $_POST['password2'];
	if(empty($name) or empty($password1) or empty($password2)){
		echo "<script>alert('请填写注册信息');history.go(-1);</script>";
		exit();
	}
	if($password1 != $password2){
		echo "<script>alert('两次输入不相同');history.go(-1);</script>";
		exit();
	}
	$selectsql = "select id from tb_member where name = '".$name."'";
	$rst = mysql_query($selectsql);
	if(mysql_num_rows($rst) != 0){
		echo "<script>alert('昵称被占用，请重新输入');history.go(-1);</script>";
		exit();
	}
	$insertsql = "insert into tb_member values('','".$name."','".md5(trim($password1))."')";
	mysql_query($insertsql);
	if(mysql_affected_rows() == 1){
		$_SESSION['name'] = $name;
		echo "<script>alert('注册成功，欢迎光临!');location='index.php';</script>";
	}
?>