PHP MySQLi-会话中未移交的变量


PHP MySQLi - Variables not handed over from session

我的会话变量被转移到所有相关的成员页面时遇到了问题。我想做的是首先将用户名和密码的输入与数据库进行匹配,一旦找到准确的成员帐户,就提取该特定成员的所有成员表信息。在提取了所有表数据后,每一列都应该分配给一个变量,然后存储在会话中以供在网站上进一步使用。

这适用于$myusername和$mypassword,但似乎不适用于任何其他变量。在另一个网站上,我只是在重复指定的$变量,值应该会弹出。

<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
// include database access information
include '../MySQL/connect_db.php';
$tbl_name = 'GPA_properties';
 // Connect to server and select databse.
$mysqli=new MySQLi("$dbhost", "$dbuser", "$dbpass", "$dbname");
if($mysqli->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
    }
// Define $myusername and $mypassword as well as escape & stripslashes to protect against MySQL injection
$myusername = stripslashes(mysqli_real_escape_string($mysqli, $_POST['myusername']));
$mypassword = stripslashes(mysqli_real_escape_string($mysqli, $_POST['mypassword']));
// Define query
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' AND password='$mypassword'";
    if(!$result = $mysqli->query($sql)){
        die('There was an error running the query [' . $db->error . ']');
    }
// count how many rows are returned
if (mysqli_num_rows($result)==1) {
    // Register $myusername, $mypassword
         $_SESSION['myusername']=$myusername;
         $_SESSION['mypassword']=$mypassword;
    // register all other data as blank first
        $activation_date = "";
        $status = "";
        $holidex = "";
        $gpa_email = "";
        $gm = "";
        $gm_email = "";
        $phone_cc = "";
        $phone = "";
        $property = "";
        $address1 = "";
        $address2 = "";
        $zip = "";
        $city = "";
        $country = "";
        // grab all other information based on username
        if ($stmt = $mysqli->prepare("SELECT Activation_Date, status, Holidex, Property_Name, GPA_Distribution_Email, General_Manager, GM_Email, Address_1, Address_2, ZIP, City, State, Country, Phone_CC, Phone FROM $tbl_name WHERE username=?")) {
            $stmt->bind_param("s", $myusername);
            $stmt->execute();
            $stmt->bind_result($activation_date, $status, $holidex, $property, $gpa_email, $gm, $gm_email, $address1, $address2, $zip, $city, $state, $country, $phone_cc, $phone);
            $stmt->fetch();
            }
        // define variables with acquired information
            $_SESSION['Activation_Date']=$activation_date;
            $_SESSION['status']=$status;
            $_SESSION['Holidex']=$holidex;
            $_SESSION['Property_Name']=$property;
            $_SESSION['GPA_Distribution_Email']=$gpa_email;
            $_SESSION['General_Manager']=$gm;
            $_SESSION['GM_Email']=$gm_email;
            $_SESSION['Address_1']=$address1;
            $_SESSION['Address_2']=$address2;
            $_SESSION['ZIP']=$zip;
            $_SESSION['City']=$city;
            $_SESSION['State']=$state;
            $_SESSION['Country']=$country;
            $_SESSION['Phone_CC']=$phone_cc;
            $_SESSION['Phone']=$phone;
            $stmt->close();
    // redirect to login_success.php
        header("location:login_success.php");
        exit;
    } else {
        echo "Wrong Username or Password";
    }
$mysqli->close();
?>

有人介意看一下吗?感谢

status是MySQL中的一个保留关键字。

在第二个查询中尝试这个:

"SELECT Activation_Date, `status`, Holidex, Property_Name, GPA_Distribution_Email, General_Manager, GM_Email, Address_1, Address_2, ZIP, City, State, Country, Phone_CC, Phone FROM $tbl_name WHERE username=?"

你会注意到单词status周围的反调(`)。这条消息告诉MySQL应该照原样读取,而不是作为关键字读取。