当前位置:首页 > PHP教程 > php应用 > 列表

php 用户注册实例代码,适合初学者

发布:smiling 来源: PHP粉丝网  添加日期:2013-12-11 13:31:58 浏览: 评论:0 
  1.  if($_POST[submit]){ 
  2.    checkusername($_POST[username]); 
  3.     if($_SESSION["code"]==$_POST[code]) 
  4.       { 
  5.     $usernamestr_replace(" ","",$_POST[username]); 
  6.     $password=md5($_POST[password].ALL_PS); 
  7.     $sql="INSERT INTO `member`.`user_list` (`uid`, `m_id`, `username`, `password`) VALUES (NULL, '$_POST[select]', '$username','$password' )"
  8.     mysql教程_query($sql); 
  9.     echo "注册成功"
  10.      } 
  11.     else 
  12.      { 
  13.       echo "验证码错误"."<br>"
  14.       session_destroy(); 
  15.      } 
  16.  } 
  17.  
  18.    function checkusername($username
  19.           { 
  20.            $sql2 = "select uid from user_list where username='".mysql_escape_string($username)."'"
  21.             $result = mysql_query($sql2or die ('ERROR: '.mysql_error()); 
  22.             if(mysql_num_rows($result)>0) 
  23.                 { 
  24.                 echo "该用户名已经存在,请更换!"
  25.                 exit(); 
  26.                  } 
  27.             else
  28.                  echo "<script> location.href='reg.php'</script>"
  29.                  } 
  30.  
  31.            } 
  32.  
  33. ?> 
  34. <LINK href="common.css" type=text/css rel=stylesheet> 
  35.   <form action="" method="post"
  36.   用户名:<input type="text" name="username" style="height:23px" /><br> 
  37.   密 码:<input type="password" name="password"  style="height:23px" /><br> 
  38.   职  位: 
  39.   <select name="select" size="1" style="height:23px" / > 
  40.     <option value="1">1</option> 
  41.     <option value="2">2</option> 
  42.   </select> 
  43.   <br/> 
  44.   
  45.  
  46.   验证码:<input type="code" name="code" size="10" style="height:23px" /> 
  47.   <img src="imgcode.php"
  48.   <br><br> 
  49.   <input type="submit" name="submit" value="注册"/> 
  50.   </form> 

Tags: 用户注册 实例 代码

分享到: