📄 register.php
字号:
<?php require_once('Connections/member.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="message.php?error=1";
$loginUsername = $_POST['txtUsername'];
$LoginRS__query = sprintf("SELECT username FROM members WHERE username=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_member, $member);
$LoginRS=mysql_query($LoginRS__query, $member) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO members (username, gender, password, birthdate, question, answer, email, introduce, regtime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['txtUsername'], "text"),
GetSQLValueString($_POST['radGender'], "text"),
GetSQLValueString($_POST['txtPassword'], "text"),
GetSQLValueString($_POST['txtBirthdate'], "date"),
GetSQLValueString($_POST['txtQuestion'], "text"),
GetSQLValueString($_POST['txtAnswer'], "text"),
GetSQLValueString($_POST['txtEmail'], "text"),
GetSQLValueString($_POST['txtIntroduce'], "text"),
GetSQLValueString($_POST['hiddenDate'], "date"));
mysql_select_db($database_member, $member);
$Result1 = mysql_query($insertSQL, $member) or die(mysql_error());
}
?>
<?php
$n = mysql_affected_rows ( $member );
if ( $n == 1 ) {
session_start();
$_SESSION["MM_Username"] = $_POST['txtUsername'];
$_SESSION['MM_UserGroup'] = 0;
header ( "Location: regok.php" );
exit;
}
?>
<!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=gb2312" />
<title>注册新会员</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function checkFormData() {
if ( form1.txtUsername.value == "" ) {
alert ( "用户名不能为空!" );
form1.txtUsername.focus();
return false;
}
if ( form1.txtPassword.value == "" ) {
alert ( "密码不能为空!" );
form1.txtPassword.focus();
return false;
}
if ( form1.txtRePassword.value == "" ) {
alert ( "请再次输入密码!" );
form1.txtRePassword.focus();
return false;
}
if ( form1.txtRePassword.value != form1.txtPassword.value ) {
alert ( "两次输入的密码必须相同!" );
form1.txtRePassword.focus();
return false;
}
if ( form1.txtBirthdate.value == "" ) {
alert ( "出生日期不能为空!" );
form1.txtBirthdate.focus();
return false;
}
var re= /^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/;
if( !re.test(form1.txtBirthdate.value) ) {
alert ( "请按YYYY-MM-DD格式输入日期!" );
form1.txtBirthdate.focus();
return false;
}
if ( form1.txtQuestion.value == "" ) {
alert ( "安全问题不能为空!" );
form1.txtQuestion.focus();
return false;
}
if ( form1.txtAnswer.value == "" ) {
alert ( "答案不能为空!" );
form1.txtAnswer.focus();
return false;
}
if ( form1.txtEmail.value == "" ) {
alert ( "电子信箱不能为空!" );
form1.txtEmail.focus();
return false;
}
if ( form1.txtEmail.value.search ("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$") != 0 ) {
alert ( "电子信箱格式不正确!" );
form1.txtEmail.focus();
return false;
}
if ( form1.txtIntroduce.value == "" ) {
alert ( "自我介绍不能为空!" );
form1.txtIntroduce.focus();
return false;
}
}
</script>
</head>
<body>
<?php include( "menu.php" ); ?>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" onsubmit="return checkFormData()">
<table width="368" border="1" align="center" bordercolor="#0066CC" rules="none">
<tr>
<th colspan="2" bgcolor="#0066CC" scope="col" class="title">注册新会员</th>
</tr>
<tr>
<td width="128" align="right">用户名:</td>
<td><input name="txtUsername" type="text" id="txtUsername" />
<font color="#000066"></font></td>
</tr>
<tr>
<td width="128" align="right">性别:</td>
<td><input name="radGender" type="radio" value="男" checked="checked" />
男
<input type="radio" name="radGender" value="女" />
女</td>
</tr>
<tr>
<td width="128" align="right">密码:</td>
<td><input name="txtPassword" type="password" id="txtPassword" /></td>
</tr>
<tr>
<td width="128" align="right">确认密码:</td>
<td><input name="txtRePassword" type="password" id="txtRePassword" /></td>
</tr>
<tr>
<td width="128" align="right">出生日期:</td>
<td><input name="txtBirthdate" type="text" id="txtBirthdate" /></td>
</tr>
<tr>
<td width="128" align="right">安全问题:</td>
<td><input name="txtQuestion" type="text" id="txtQuestion" /></td>
</tr>
<tr>
<td width="128" align="right">答案:</td>
<td><input name="txtAnswer" type="text" id="txtAnswer" /></td>
</tr>
<tr>
<td width="128" align="right">电子信箱:</td>
<td><input name="txtEmail" type="text" id="txtEmail" /></td>
</tr>
<tr>
<td width="128" align="right">自我介绍: </td>
<td><textarea name="txtIntroduce" rows="3" id="txtIntroduce"></textarea></td>
</tr>
<tr>
<td width="128" height="32" align="right"><input name="hiddenDate" type="hidden" id="hiddenDate" value="<?php echo date("Y-m-d H:i:s"); ?>" /></td>
<td height="32"><input type="submit" name="Submit" value="注册" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -