註冊頁面php驗證使用者名稱是否存在。_PHP教程
• php教程• 發佈:2018-10-06
reg.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 6 <link rel="stylesheet" type="text/css" href="css/int.css" /> 7 <script type="text/javascript" src="js/func.js"></script> 8 <style type="text/css"> 9 td{ 10 height:30px; 11 vertical-align:middle; 12 align:center; 13 } 14 #myText{ 15 width:600px; 16 } 17 </style> 18 <title>註冊頁面</title> 19 </head> 20 21 <body > 22 23 <?php 24 error_reporting(0); 25 //不讓PHP報告有錯語發生。如果不關閉好有類似這的錯語 Warning: preg_match() 關閉就不出現了 26 session_start(); 27 header("Cache-control: private"); 28 29 $conn = @ mysql_connect("localhost","root","")or die("資料庫連線錯誤"); 30 mysql_select_db("bbs",$conn); 31 mysql_query("set names utf8"); 32 33 if($_POST['submit']) 34 { 35 $username = $_POST["username"]; 36 37 $sql="select userName from user_info where userName='$username'"; 38 // echo $sql; 39 40 $query=mysql_query($sql); 41 $rows = mysql_num_rows($query); 42 if($rows > 0){ 43 echo "<script type='text/javascript'>alert('使用者名稱已存在');location='javascript:history.back()';</script>"; 44 }else{ 45 $user_in = "insert into user_info (username,pass,sex,qq,email,img) values ('$_POST[username]',md5('$_POST[pass]'),'$_POST[sex]','$_POST[qq]','$_POST[email]','$_POST[img_select]')"; 46 //echo $user_in; 47 mysql_query($user_in); 48 echo "<script type='text/javascript'>alert('寫入成功!!');location.href='login.php';</script>"; 49 50 } 51 52 //javascript:history.go(-1) 53 54 } 55 ?> 56 57 58 <form action="reg.php" name="reg_form" method="post" onsubmit="return check_reg()"> 59 <table name="reg_table" align="left"> 60 <tr> 61 <td>使用者:</td><td><input id="username" name="username" class="myText" type="text" maxlength="12" /></td> 62 </tr> 63 64 <tr> <!--性別:0 保密 1 女 2 男--> 65 <td > 性別:</td> 66 <td>女<input type="radio" value="1" name="sex"/> 67 男<input type="radio" value="2" name="sex" /> 68 保密<input type="radio" value="0" name="sex" checked/></td> 69 </tr> 70 71 <tr> 72 <td>密碼:</td><td><input name="pass" class="myText" type="password" onblur="check_len(this)"/><span id="show_pass" style="color:red;"></td> 73 </tr> 74 75 <tr> 76 <td>重複密碼:</td><td><input name="repass" class="myText" type="password" onblur="check_pass(this)" /><span id="show_repass" style="color:red;"></td> 77 </tr> 78 79 <tr> 80 <td>QQ:</td><td><input type="text" class="myText" name="qq" onblur="check_qq(this)"/><span style="color:red;" id="show_qq"></td> 81 </tr> 82 83 <tr> 84 <td>郵箱:</td><td><input type="text" class="myText" name="email" onblur="check_email(this)"/><span id="show_e" style="color:red;"></td> 85 </tr> 86 87 <tr> 88 <td height="60">頭像:</td> 89 <td> 90 <select name="img_select" onchange="img_change(this)"> 91 <option value="101" >女 001</option> 92 <option value="102" >女 002</option> 93 <option value="103" >女 003</option> 94 <option value="104" >女 004</option> 95 <option value="105" >男 001</option> 96 <option value="106" >男 002</option> 97 <option value="107" >男 003</option> 98 <option value="108" >男 004</option> 99 </select>100 <img src="/bbs/img/101.gif" id="tx_change" style="width:50px; height:65px;" alt=""/>101 </td>102 </tr>103 104 <tr height="20" align="justify">105 <td align="right" ><input type="submit" value="註冊" name="submit" style="margin-right:5px;"/></td>106 <td><input type="reset" value="重置" name="reset" style="margin-left:5px;"/></td>107 </tr>108 109 <tr>110 <td colspan="2">我已有賬號現在<a href="login.php">登入</a></td>111 </tr>112 113 </table>114 </form>115 </body>116 </html>