php 代碼 100分

來源:互聯網
上載者:User
求一個用php做的註冊和登入頁面能提交到mysql的,連接埠是3307,資料庫名是bbs,
表名是user-info,註冊的是register.php 登入的是login.php
求代碼,用來參考學習


回複討論(解決方案)

這種代碼網上很多吧,隨便一搜一大把。

其實php的登入註冊,說白了就是php執行select跟insert SQL語句,然後做些相應的跳轉。

我想要的是代碼,能給我提供學習

騷年,百度/google一下就有了,何必在這等別人給你寫呢

隨便下載個開源的你就可以看到了。

不是這缺就是哪個對方不對的,改起來麻煩,我對php還不是很熟悉,我是做java 我們部門要求掌握php的一些基礎知識,所以嘍

execute_dql($sql)){if(md5($pwd)==$user_exists[0]['pwd']){session_start();$_SESSION['username']=$user_exists[0]['name'];echo 1;exit();}}else{echo -1;exit();}}elseif($_POST['type']=='reg'){$username=addslashes($_POST['username']);$pwd=md5($_POST['pwd']);$sql_exists="SELECT * FROM test WHERE name='$username'";//test改為user-info$db=new DB();if($db->execute_dql($sql_exists)){//已存在該使用者echo -2;exit();}$sql="INSERT INTO test(name,pwd) VALUES('$username','$pwd')";//test改為user-infoif($code=$db->execute_dml($sql)){session_start();$_SESSION['username']=stripslashes($username);echo 1;exit();}else{echo -1;exit();}}class DB{private $conn;private $host="localhost";//localhost:3307private $user="root";private $password="123456";private $db="test";//bbsprivate $res;function __construct(){$this->conn=mysql_connect($this->host,$this->user,$this->password);if(!$this->conn){die("串連資料庫失敗".mysql_error());}mysql_select_db($this->db,$this->conn);mysql_query("SET NAMES utf8");}function execute_dql($sql){$this->res=mysql_query($sql,$this->conn) or die(mysql_error());$r=array();while($row=mysql_fetch_assoc($this->res)){$r[]=$row;}return $r;}function execute_dml($sql){$b=mysql_query($sql,$this->conn) or die(mysql_error());if(!$b){return 0;//失敗}else{if(mysql_affected_rows($this->conn)>0){return 1;//成功}else{return 2;//沒有影響到行數}}}function __destruct(){if(!empty($this->res)){mysql_free_result($this->res);}mysql_close($this->conn);}}?>


exe.php
execute_dql($sql)){if(md5($pwd)==$user_exists[0]['pwd']){session_start();$_SESSION['username']=$user_exists[0]['name'];echo 1;exit();}}else{echo -1;exit();}}elseif($_POST['type']=='reg'){$username=addslashes($_POST['username']);$pwd=md5($_POST['pwd']);$sql_exists="SELECT * FROM test WHERE name='$username'";//test改為user-info$db=new DB();if($db->execute_dql($sql_exists)){//已存在該使用者echo -2;exit();}$sql="INSERT INTO test(name,pwd) VALUES('$username','$pwd')";//test改為user-infoif($code=$db->execute_dml($sql)){session_start();$_SESSION['username']=stripslashes($username);echo 1;exit();}else{echo -1;exit();}}class DB{private $conn;private $host="localhost";//localhost:3307private $user="root";private $password="123456";private $db="test";//bbsprivate $res;function __construct(){$this->conn=mysql_connect($this->host,$this->user,$this->password);if(!$this->conn){die("串連資料庫失敗".mysql_error());}mysql_select_db($this->db,$this->conn);mysql_query("SET NAMES utf8");}function execute_dql($sql){$this->res=mysql_query($sql,$this->conn) or die(mysql_error());$r=array();while($row=mysql_fetch_assoc($this->res)){$r[]=$row;}return $r;}function execute_dml($sql){$b=mysql_query($sql,$this->conn) or die(mysql_error());if(!$b){return 0;//失敗}else{if(mysql_affected_rows($this->conn)>0){return 1;//成功}else{return 2;//沒有影響到行數}}}function __destruct(){if(!empty($this->res)){mysql_free_result($this->res);}mysql_close($this->conn);}}?>

上面發錯了,前台頁面,用了jquery

登入

使用者名稱:
密 碼:

註冊

使用者名稱:
密 碼:
確 認:

樓主你贏啦。

網上有好多啊,搜一搜。

搜搜更健康。

多看看就有的,加油樓主

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.