我有一张桌子,它有更多列:
id | username | picture
图片是varchar类型,它保留用户图片的路径 用户名是varchar并且是唯一的
<?php
session_start();
if (isset($_POST["logIn"])) {
$connection = new mysqli(...);
$email = $connection->real_escape_string($_POST["email"]);
$password = sha1($connection->real_escape_string($_POST["password"]));
$data = $connection->query("SELECT * FROM users WHERE email='$email' AND password='$password'");
if ($data->num_rows > 0) {
$_SESSION["email"] = $email;
$_SESSION["loggedIn"] = 1;
$picture = $connection->query("SELECT picture FROM users WHERE email='$email' AND password='$password'");
$_SESSION["picture"]=$picture;
header("Location:../index.php");
exit();
}
所以我想做的是,创建一个$_SESSION["picture"]
变量,该变量将保留用户名图片的值,我的意思是试图立即登录的用户的图片
答案 0 :(得分:0)
您必须调用提取函数才能从表中获取数据。
$data = $connection->query("SELECT picture FROM users WHERE email='$email' AND password='$password'");
if ($data->num_rows > 0) {
$row = $data->fetch_assoc();
$_SESSION["email"] = $email;
$_SESSION["loggedIn"] = 1;
$_SESSION["picture"]=$row['picture'];
header("Location:../index.php");
exit();
}