php用戶注冊(前台完美js驗證)
php教程用戶注冊(前台完美網頁特效驗證)
/*
create table `member` (
`member_account` varchar(25) collate utf8_unicode_ci not null,
`member_password` varchar(32) collate utf8_unicode_ci not null,
`member_name` varchar(20) collate utf8_unicode_ci not null,
`sex` varchar(1) collate utf8_unicode_ci not null,
`schoolnumber` varchar(10) collate utf8_unicode_ci not null,
`phonenumber` varchar(15) collate utf8_unicode_ci not null,
`email` varchar(50) collate utf8_unicode_ci not null,
unique key `member_account` (`member_account`)
) engine=innodb default charset=utf8 collate=utf8_unicode_ci;
*/
?>
<!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 align="center"><font face="楷書" size="+3">會員注冊</font></div>
<form id="form1" name="form1" method="get" action="register_get.php">
<table width="695" border="1" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="167">賬號:(account)</td>
<td width="416"><input name="m_acct" type="text" id="m_acct" value="<?php if(!empty($_get['m_acct']))
echo $_get['m_acct'];
?>" maxlength="20" />
<font color="#ff0000"> *</font>(由20個數字或字母組成)</td>
</tr>
<tr>
<td>密碼:(password)</td>
<td><input name="m_pw" type="password" id="m_pw" maxlength="20" />
<font color="#ff0000"> *</font>(由20個數字或字母組成)</td>
</tr>
<tr>
<td>確認密碼(password)</td>
<td><input type="password" name="pass" id="pass" />
<font color="#ff0000"> *</font>(再次輸入密碼)</td>
</tr>
<tr>
<td>真實姓名:(name)</td>
<td><input type="text" name="m_name" id="m_name" value="<?php if(!empty($_get['m_name']))
echo $_get['m_name'];
?>" /></td>
</tr>
<tr>
<td>性別:(sex)</td>
<td align="left"><p>
<label>
<input name="m_sex" type="radio" id="radiogroup1_0" value="男" />
男</label>
<label>
<input type="radio" name="m_sex" value="女" id="radiogroup1_1" />
女 <font color="#ff0000"> *</font></label>
</td>
</tr>
<tr>
<td>學號:(school number)</td>
<td><input type="text" name="m_snum" id="m_snum" value="<?php if(!empty($_get['m_snum']))
echo $_get['m_snum'];
?>" /></td>
</tr>
<tr>
<td>手機號碼:(mobil phone)</td>
<td><input type="text" name="m_pnum" id="m_pnum" value="<?php if(!empty($_get['m_pnum']))
echo $_get['m_pnum'];
?>"/></td>
</tr>
<tr>
<td>電子郵箱:(email)</td>
<td><input type="text" name="m_email" id="m_email" value="<?php if(!empty($_get['m_email']))
echo $_get['m_email'];
?>"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="reset" name="button" id="button" value="重置表單" />
<input type="submit" name="button2" id="button2" value="確定注冊" /></td>
</tr>
</table>
</form></p>
<p align="center">以上打"*"為必填項</p>
</body>
</html>register_get.php文件
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>提示</title>
</head>
<?php
if(empty($_get['m_acct']))
echo "賬號不能為空!<a href='register.php?m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_snum=".$_get['m_snum']."&m_pnum=".$_get['m_pnum']."'>返回重新注冊。</a></p>";
else if(empty($_get['m_pw']))
echo "密碼不能為空!<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_snum=".$_get['m_snum']."&m_pnum=".$_get['m_pnum']."&m_email=".$_get['m_email']."'>返回重新注冊。</a></p>";
else if($_get['m_pw']!=$_get['pass'])
echo "兩次輸入的密碼不一樣,<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_snum=".$_get['m_snum']."&m_pnum=".$_get['m_pnum']."'>返回重新注冊。</p>";
else if(empty($_get['m_sex']))
echo "未輸入性別,<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_snum=".$_get['m_snum']."&m_pnum=".$_get['m_pnum']."'>返回重新注冊。</a></p>";
else if(!empty($_get['m_snum'])&&!is_numeric($_get['m_snum']))
echo "學號必須全為數字,<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_pnum=".$_get['m_pnum']."'>返回重新注冊。</a></p>";
else if(!empty($_get['m_pnum'])&&!is_numeric($_get['m_pnum']))
echo "手機號碼必須全為數字,<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_snum=".$_get['m_snum']."'>返回重新注冊。</a></p>";
else if(!empty($_get['m_email'])&&!ereg("([0-9a-za-z]+)([@])([0-9a-za-z]+)(.)([0-9a-za-z]+)",$_get['m_email']))
echo "郵箱輸入不合法!<a href='register.php?m_acct=".$_get['m_acct']."&m_name=".$_get['m_name']."&m_sex=".$_get['m_sex']."&m_snum=".$_get['m_snum']."&m_pnum=".$_get['m_pnum']."'>返回重新注冊。</a></p>";
else
{
require_once ('inc.php');
$_session['pass']="ok";
$_session['member']=$_get['m_acct'];
$link = getdblink();
$sql="insert into member values('".$_get['m_acct']."','".md5($_get['m_pw'])."','".$_get['m_name']."','".$_get['m_sex']."','".$_get['m_snum']."','".$_get['m_pnum']."','".$_get['m_email']."')";
$result=mysql教程_query($sql)or die(mysql_error());
if($result>0)
echo "".$_get['m_name'].",恭喜你注冊成功,<a href='member_index.php'>馬上進入主頁面...</p>";
else
{
$_session['pass']="no pass";
echo "注冊失敗!<a href-'register.php'>重新注冊。</a></p>";
mysql_close();
}
}
?>
<body>
</body>
</html>