<?php


require( "_inc.php" );
$userName = !empty( $_POST['userName'] ) ? trim( $_POST['userName'] ) : "";
$userPwd = !empty( $_POST['userPwd'] ) ? trim( $_POST['userPwd'] ) : "";
$userPwd2 = !empty( $_POST['userPwd2'] ) ? trim( $_POST['userPwd2'] ) : "";
$authCode = !empty( $_POST['authCode'] ) ? trim( $_POST['authCode'] ) : "";
if ( $authCode != $_SESSION['ses_authCode'] )
{
	exit( "操作失败<br>验证码不正确。" );
}
if ( empty( $userName ) || empty( $userPwd ) )
{
	exit( "操作失败<br>请输入用户名和密码。" );
}
if ( $userPwd != $userPwd2 )
{
	exit( "操作失败<br>您两次输入的密码不相同。" );
}
$sql = "SELECT f_id FROM ".$gDb['prefix'].( "users WHERE (f_userName='".$userName."')" );
$arrUserInfo = $db->fetchrow( $sql );
if ( !empty( $arrUserInfo['f_id'] ) )
{
	exit( "操作失败<br>用户名“ ".$userName." ”已经被注册了。" );
}
$now = time( );
$ip = $_SERVER['REMOTE_ADDR'];
$userPwd = md5( $userPwd );
$sql = "INSERT INTO ".$gDb['prefix'].( "users SET f_userName='".$userName."',\r\n                                                 f_pwd='{$userPwd}',\r\n                                                 f_regTime='{$now}',\r\n                                                 f_regIp='{$ip}'" );
$db->query( $sql );
header( "location: register_done.php" );
?>
