第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php實現(xiàn)登錄注冊 數(shù)據(jù)庫

php實現(xiàn)登錄注冊 數(shù)據(jù)庫

森林海 2019-03-01 10:34:51
php實現(xiàn)登錄注冊的時候,數(shù)據(jù)庫部分不會弄,請大神幫忙解決問題,謝謝!已經(jīng)創(chuàng)建了test表。下面我貼上代碼:第一部分:(login.html) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>用戶登錄</title> <style type="text/css"> button,input{padding:0px;} html{font-size:12px;} fieldset{width:300px; margin: 0 auto;} legend{font-weight:bold; font-size:14px;} .label{float:left; width:70px; margin-left:10px;} .left{margin-left:80px; width: 65px;} .input{width:150px;} span{color: #666666;} .right a{ text-decoration: none; color:#000; display: block; width:100%; height: 100%; position: relative; z-index: 999; } .right{ width: 65px; margin-left:20px; } </style> <script language=JavaScript> <!-- function InputCheck(LoginForm) { if (LoginForm.username.value == "") { alert("請輸入用戶名!"); LoginForm.username.focus(); return (false); } if (LoginForm.password.value == "") { alert("請輸入密碼!"); LoginForm.password.focus(); return (false); } } //--> </script> </head> <body> <div> <fieldset> <legend>用戶登錄</legend> <form name="LoginForm" method="post" action="login.php" onSubmit="return InputCheck(this)"> <p> <label for="username" class="label">用戶名:</label> <input id="username" name="username" type="text" class="input" /> <p/> <p> <label for="password" class="label">密 碼:</label> <input id="password" name="password" type="password" class="input" /> <p/> <p> <input type="submit" name="submit" value=" 確 定 " class="left" /> <button name="button" value=" 注冊 " class="right" /><a href = "reg.html">注冊</a></button> </p> </form> </fieldset> </div> </body> </html> 第二部分:(login.php): <?php session_start(); //注銷登錄 if($_GET['action'] == "logout"){ unset($_SESSION['userid']); unset($_SESSION['username']); echo '注銷登錄成功!點擊此處 <a href="login.html">登錄</a>'; exit; } //登錄 if(!isset($_POST['submit'])){ exit('非法訪問!'); } $username = htmlspecialchars($_POST['username']); $password = MD5($_POST['password']); //包含數(shù)據(jù)庫連接文件 include('conn.php'); //檢測用戶名及密碼是否正確 $check_query = mysql_query("select uid from user where username='$username' and password='$password' limit 1"); if($result = mysql_fetch_array($check_query)){ //登錄成功 $_SESSION['username'] = $username; $_SESSION['userid'] = $result['uid']; echo $username,' 歡迎你!進入 <a href="my.php">用戶中心</a><br />'; echo '點擊此處 <a href="login.php?action=logout">注銷</a> 登錄!<br />'; exit; } else { exit('登錄失??!點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試'); } ?> 第三部分:(reg.html): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>用戶注冊</title> <style type="text/css"> button,input{padding:0px;} html{font-size:12px;} fieldset{width:520px; margin: 0 auto;} legend{font-weight:bold; font-size:14px;} label{float:left; width:70px; margin-left:10px;} .left{margin-left:80px; width:90px;} .input{width:150px;} span{color: #666666;} .right a{ text-decoration: none; color:#000; display: block; width:100%; height: 100%; position: relative; z-index:999; } .right{ width:90px; margin-left:20px; } </style> <script language=JavaScript> <!-- function InputCheck(RegForm) { if (RegForm.username.value == "") { alert("用戶名不可為空!"); RegForm.username.focus(); return (false); } if (RegForm.password.value == "") { alert("必須設定登陸密碼!"); RegForm.password.focus(); return (false); } if (RegForm.repass.value != RegForm.password.value) { alert("兩次密碼不一致!"); RegForm.repass.focus(); return (false); } if (RegForm.email.value == "") { alert("電子郵箱不可為空!"); RegForm.email.focus(); return (false); } } //--> </script> </head> <div> <fieldset> <legend>用戶注冊</legend> <form name="RegForm" method="post" action="reg.php" onSubmit="return InputCheck(this)"> <p> <label for="username" class="label">用戶名:</label> <input id="username" name="username" type="text" class="input" /> <span>(必填,3-15字符長度,支持漢字、字母、數(shù)字及_)</span> <p/> <p> <label for="password" class="label">密 碼:</label> <input id="password" name="password" type="password" class="input" /> <span>(必填,不得少于6位)</span> <p/> <p> <label for="repass" class="label">重復密碼:</label> <input id="repass" name="repass" type="password" class="input" /> <p/> <p> <label for="email" class="label">電子郵箱:</label> <input id="email" name="email" type="text" class="input" /> <span>(必填)</span> <p/> <p> <input type="submit" name="submit" value=" 提交注冊 " class="left" /> <button name = "button" class = "right"><a href="login.html">返回登錄</a></button> </p> </form> </fieldset> </div> <body> </body> </html> 第四部分:(reg.php): <?php if(!isset($_POST['submit'])){ exit('非法訪問!'); } $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; //注冊信息判斷 if(!preg_match('/^[\w\x80-\xff]{3,15}$/', $username)){ exit('錯誤:用戶名不符合規(guī)定。<a href="javascript:history.back(-1);">返回</a>'); } if(strlen($password) < 6){ exit('錯誤:密碼長度不符合規(guī)定。<a href="javascript:history.back(-1);">返回</a>'); } if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', $email)){ exit('錯誤:電子郵箱格式錯誤。<a href="javascript:history.back(-1);">返回</a>'); } //包含數(shù)據(jù)庫連接文件 include('conn.php'); //檢測用戶名是否已經(jīng)存在 $check_query = mysql_query("select uid from user where username='$username' limit 1"); if(mysql_fetch_array($check_query)){ echo '錯誤:用戶名 ',$username,' 已存在。<a href="javascript:history.back(-1);">返回</a>'; exit; } //寫入數(shù)據(jù) $password = MD5($password); $regdate = time(); $sql = "INSERT INTO user(username,password,email,regdate)VALUES('$username','$password','$email',$regdate)"; if(mysql_query($sql,$conn)){ exit('用戶注冊成功!點擊此處 <a href="login.html">登錄</a>'); } else { echo '抱歉!添加數(shù)據(jù)失?。?,mysql_error(),'<br />'; echo '點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試'; } ?> 第五部分:(my.php): <?php session_start(); //檢測是否登錄,若沒登錄則轉向登錄界面 if(!isset($_SESSION['userid'])){ header("Location:login.html"); exit(); } //包含數(shù)據(jù)庫連接文件 include('conn.php'); $userid = $_SESSION['userid']; $username = $_SESSION['username']; $user_query = mysql_query("select * from user where uid=$userid limit 1"); $row = mysql_fetch_array($user_query); echo '用戶信息:<br />'; echo '用戶ID:',$userid,'<br />'; echo '用戶名:',$username,'<br />'; echo '郵箱:',$row['email'],'<br />'; echo '注冊日期:',date("Y-m-d", $row['regdate']),'<br />'; echo '<a href="login.php?action=logout">注銷</a> 登錄<br />'; ?> 最關鍵的一部分 :(conn.php): <?php /***************************** *數(shù)據(jù)庫連接 *****************************/ $conn = @mysql_connect("112.74.164.248","root","root"); if (!$conn){ die("連接數(shù)據(jù)庫失?。? . mysql_error()); } mysql_select_db("test", $conn); //字符轉換,讀庫 mysql_query("set character set 'gbk'"); //寫庫 mysql_query("set names 'gbk'"); ?>
查看完整描述

3 回答

?
當年話下

TA貢獻1890條經(jīng)驗 獲得超9個贊

$sql = "insert into test values(f1,f2,f3,f4...)";
$res = mysql_query($conn,$sql);

查看完整回答
反對 回復 2019-03-01
?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊

我想問一下你的PHP是什么版本的,在5.5以后mysql_query()的連接方法就廢棄了。建議使用PDO去鏈接數(shù)據(jù)庫。

查看完整回答
反對 回復 2019-03-01
?
MM們

TA貢獻1886條經(jīng)驗 獲得超2個贊

郵箱不用檢測是否已存在?

查看完整回答
反對 回復 2019-03-01
  • 3 回答
  • 0 關注
  • 1206 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號