嗨,我爲一個網站進行了登錄。在單個數據庫中使用2個表登錄的不同方式
我做在一個數據庫中使用一個賬戶表一個,成功一個。
現在我又爲另一個帳戶創建了另一個表。兩個表的屬性都不同,所以我將它們分開。
我用這個algorithim具有在困難時期登錄第二個。
輸入的登錄名和密碼都來自使用HTML表單的另一頁。
<?php
//Start session
session_start();
//Include database connection details
require_once("config.php");
require("clean.php");
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: login-form.php");
exit();
}
//Create query for patient
$qry="SELECT * FROM user_info WHERE login='$login' AND password='".md5($password)."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful User
session_regenerate_id();
$user_info = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $user_info['ID_NO'];
$_SESSION['SESS_FIRST_NAME'] = $user_info['FNAME'];
$_SESSION['SESS_admin'] = $user_info['admin'];
$_SESSION['SESS_itResult'] = $user_info['itResult'];
//print "Login a success!";
session_write_close();
header("location: member-index.php");
exit();
}
else {
//Create query for
$qry="SELECT * FROM specialist_info WHERE spec_username='$login' AND spec_password='".md5($password)."'";
$result2=mysql_query($qry);
//Check whether the query was successful or not
if($result2) {
if(mysql_num_rows($result2) == 1) {
//Login Successful User
session_regenerate_id();
$specialist_info = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $specialist_info['spec_id'];
$_SESSION['SESS_FIRST_NAME'] = $specialist_info['name'];
$_SESSION['SESS_admin'] = 1;
//print "Login a success!";
session_write_close();
header("location: member-index.php");
exit();
}
else {
//Login failed
header("location: login-failed.php");
exit();
}
}
}
}
else {
die("Query failed");
}
}
?>
我能夠登錄在第(意思是有PHP和MySQL之間的連接)佔然而我不能在第二位。
從我跟着,我無法在此一贈。 「if(mysql_num_rows($ result2)== 1)」 我知道數據庫中的第二個表中存在數據,因爲我檢查了它(有MD5是)。
也許我的邏輯錯了。建議? :D謝謝!
會試試謝謝! – 2011-03-31 12:21:38
如果答案有幫助,甚至更好,解決您的問題,請考慮接受或投票。 var_dump顯示了什麼? – 2011-03-31 18:22:22
int(0),所以查詢> _ < – 2011-04-01 06:14:55