0
我創建了兩個表,這些主要領域:MySQL的加入查詢從PHP腳本
- registered_users(registration_id,名字,姓氏,LOGIN_ID,密碼)
- users_profile(PROFILE_ID,registration_id,FIRST_NAME,姓氏,關係類型,地址,電話)
我創建了一個login.php文件,在registered_users上運行查詢來檢查loginid和password以及成功的登錄調用welcome.php文件。
我已經能夠在registered_users表上執行查詢(檢查登錄),但是我需要一些幫助來編寫一個查詢,這將幫助我從users_profile表中檢索與登錄用戶的registration_id相匹配的那些配置文件。
//login.php
<?php
if (isset($_POST["loginid"]))
{
$logid=strtolower($_POST["loginid"]);
$passwd=$_POST["password"];
require_once 'connection.php';
$q="select email,password,registeration_id from registered_users where email='$logid'";
$result=mysqli_query($conn,$q);
$row = mysqli_fetch_array($result);
if ($row["password"] == $passwd && $row["email"]==$logid)
{
session_start();
$_SESSION["login"] = $logid;
// I need to nest a query here to select ONLY those profiles that belong to logged-in user
$regid=$_row["registeration_id"];
$q2="SELECT registered_users.Registeration_id,profile.Relation_type,profile.first_name,profile.last_name from registered_users,profile WHERE registered_users.Registeration_id=$regid";
$result2=mysqli_query($conn,$q2);
$row2 = mysqli_fetch_array($result2);
$_SESSION["fnm"]= $row2["first_name"];
$_SESSION["lnm"]= $row2["last_name"];
$_SESSION["rtyp"]= $row2["relation_type"];
header("Location: Welcome.php");
}
else
{
echo "Wrong Username or Password!";
}
?>
的代碼包含SQL連接查詢,需要加以固定。
事實上,它在兩張桌子上都沒有使用連接。我寧願用這個查詢來獲取結果: $ q2 =「SELECT registeration_id,relation_type,first_name,last_name FROM profile WHERE registeration_id ='$ regid'」; – Kam