我有一个文件,用于传递$ _SESSION数据库的内容
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
$sql = "SELECT * FROM users WHERE user_uid = '$uid' OR user_email = '$uid'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result)
$_SESSION['u_id'] = row['user_id'];
$_SESSION['u_first'] = row['user_first'];
$_SESSION['u_last'] = row['user_last'];
$_SESSION['u_email'] = row['user_email'];
$_SESSION['u_uid'] = row['user_uid'];
header("Location: ../index.php?login=sucess");
在我的头文件中,我使用附加到index.php的session_start()开始会话。
<?php
include_once 'header.php';
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Home</h2>
<?php
if (isset($_SESSION['u_id'])) {
echo "Bem-vindo!";
print_r($_SESSION);
}
?>
</div>
</section>
<?php
include_once 'footer.php';
?>
就是这样: enter image description here
所以看来我的数组都充满了“ r”,我真的不知道为什么,有什么想法吗?
答案 0 :(得分:1)
请更新$row
而不是row
示例
$_SESSION['u_id'] = row['user_id'];
替换为
$_SESSION['u_id'] = $row['user_id'];
所有变量。
答案 1 :(得分:1)
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
$sql = "SELECT * FROM users WHERE user_uid = '$uid' OR user_email = '$uid'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result)
session_start(); // You need to this function
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../index.php?login=sucess");
答案 2 :(得分:0)
由于您错过了$
变量row
。它应该像$row['user_id']
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];