php 用戶注冊實例代碼,適合初學者
來源:程序員人生 發布時間:2013-10-10 07:12:07 閱讀次數:3231次
- if($_POST[submit]){
- checkusername($_POST[username]);
- if($_SESSION["code"]==$_POST[code])
- {
- $username= str_replace(" ","",$_POST[username]);
- $password=md5($_POST[password].ALL_PS);
- $sql="INSERT INTO `member`.`user_list` (`uid`, `m_id`, `username`, `password`) VALUES (NULL, '$_POST[select]', '$username','$password' )";
- mysql教程_query($sql);
- echo "注冊成功";
- }
- else
- {
- echo "驗證碼錯誤"."<br>";
- session_destroy();
- }
- }
-
- function checkusername($username)
- {
- $sql2 = "select uid from user_list where username='".mysql_escape_string($username)."'";
- $result = mysql_query($sql2) or die ('ERROR: '.mysql_error());
- if(mysql_num_rows($result)>0)
- {
- echo "該用戶名已經存在,請更換!";
- exit();
- }
- else{
- echo "<script> location.href='reg.php'</script>";
- }
-
- }
-
- ?>
- <LINK href="common.css" type=text/css rel=stylesheet>
- <form action="" method="post">
- 用戶名:<input type="text" name="username" style="height:23px" /><br>
- 密 碼:<input type="password" name="password" style="height:23px" /><br>
- 職 位:
- <select name="select" size="1" style="height:23px" / >
- <option value="1">1</option>
- <option value="2">2</option>
- </select>
- <br/>
-
-
- 驗證碼:<input type="code" name="code" size="10" style="height:23px" />
- <img src="imgcode.php">
- <br><br>
- <input type="submit" name="submit" value="注冊"/>
- </form>
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
------分隔線----------------------------
------分隔線----------------------------