php mysql登陆页面完整代码_求助:PHP实现登陆注册的代码是什么啊(主要是数据库那块)?...
思路:
注冊:
獲取前臺表單數(shù)據(jù)->數(shù)據(jù)庫連接->判斷數(shù)據(jù)是否存在,存在輸出提示,不存在則向數(shù)據(jù)庫插入表單傳來的值->如果sql執(zhí)行失敗輸出錯誤,成功功輸出注冊成功
登陸:
獲取前臺表單數(shù)據(jù)->數(shù)據(jù)庫連接->判斷前臺輸入的用戶名和密碼是否在數(shù)據(jù)庫中存在>如果查詢無數(shù)據(jù)則提示登陸失敗,如果查詢成功則session把用戶名保存,登陸成功。
具體代碼可以從網(wǎng)上找,一查一大把。
if(!isset($_POST['submit'])){
exit("錯誤執(zhí)行");
}//判斷是否有submit操作
$name=$_POST['name'];//post獲取表單里的name
$password=$_POST['password'];//post獲取表單里的password
include('connect.php');//鏈接數(shù)據(jù)庫
$q="insert into user(id,username,password) values (null,'$name','$password')";//向數(shù)據(jù)庫插入表單傳來的值的sql
$reslut=mysql_query($q,$con);//執(zhí)行sql
if (!$reslut){
die('Error: ' . mysql_error());//如果sql執(zhí)行失敗輸出錯誤
}else{
echo "注冊成功";//成功輸出注冊成功
}
mysql_close($con);//關(guān)閉數(shù)據(jù)庫
if(!isset($_POST["submit"])){
exit("錯誤執(zhí)行");
}//檢測是否有submit操作
include('connect.php');//鏈接數(shù)據(jù)庫
$name = $_POST['name'];//post獲得用戶名表單值
$passowrd = $_POST['password'];//post獲得用戶密碼單值
if ($name && $passowrd){//如果用戶名和密碼都不為空
$sql = "select * from user where username = '$name' and password='$passowrd'";//檢測數(shù)據(jù)庫是否有對應(yīng)的username和password的sql
$result = mysql_query($sql);//執(zhí)行sql
$rows=mysql_num_rows($result);//返回一個數(shù)值
if($rows){//0 false 1 true
header("refresh:0;url=welcome.html");//如果成功跳轉(zhuǎn)至welcome.html頁面
exit;
}else{
echo "用戶名或密碼錯誤";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";//如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
}
}else{//如果用戶名或密碼有空
echo "表單填寫不完整";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
//如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
}
mysql_close();//關(guān)閉數(shù)據(jù)庫
總結(jié)
以上是生活随笔為你收集整理的php mysql登陆页面完整代码_求助:PHP实现登陆注册的代码是什么啊(主要是数据库那块)?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#中的函数参数能不能有默认值的解决方法
- 下一篇: gentoo安装记录[20050216]