php實現使用者註冊的程式碼範例

來源:互聯網
上載者:User
本文介紹下,php實現的使用者註冊資訊檢測與入庫的例子,有需要的朋友參考下吧。

代碼如下:

query('set names gb2312');if(empty($conn)){   die("資料庫連接失敗");}$UserName=$_POST['username'];$pwd=$_POST['password'];$email=$_POST['email'];$sex=$_POST['sex'];$time=time();$code=strtolower($_POST["code"]);$str="select * from users where username='".$username."'";   $result1=$conn->query($str);   $row=$result1->fetch_row();if($row){ $temp="已有人註冊此名,請重新選擇名字!"; echo $temp;echo"返回";} else {if( $_SESSION['sname']==$code){   echo $temp="認證碼成功";   $sql="INSERT INTO users VALUES('$username', '$password','$email','$sex','$time')";   $result=$conn->query($sql);   if($result==true)      {      $_SESSION['mail']="註冊成功,請登陸";      echo "";      }      else {echo "註冊失敗".mysql_error();}} else {echo "認證碼錯誤";}}?>

以上代碼,接收註冊頁傳來的參數,包括使用者名稱,密碼,郵箱,性別,驗證碼等。然後,檢測是否登入過,否則將註冊資訊寫入資料庫。很簡單,特別適合新手朋友參考。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.