加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 20:39:56 所属栏目:PHP教程 来源:网络整理
导读:if ( $_POST [submit]){ checkusername( $_POST [username]); if ( $_SESSION [ code ]== $_POST [code]) { $username = str_replace ( , , $_POST [username]); $password =md5( $_POST [password].ALL_PS); $sql = INSERTINTO`member`.`user_list`(`uid`,`
  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> 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读