求一個用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
登入
使用者名稱:
密 碼:
註冊
使用者名稱:
密 碼:
確 認:
樓主你贏啦。
網上有好多啊,搜一搜。
搜搜更健康。
多看看就有的,加油樓主