【发布时间】:2013-04-16 20:31:46
【问题描述】:
这是来自我的登录功能的简短代码。我在尝试从特定用户获取 id 并将其索引到新会话时遇到问题。 代码已注释,希望大家能帮帮我。
$email = mysql_real_escape_string($_POST['email']);
$password = md5(mysql_real_escape_string($_POST['password']));
include_once("include/connection.php");
$query = "SELECT email,password,id FROM user WHERE email ='".$email."' AND password='".$password."'";
$result = mysqli_query($ligaBD,$query);
$value= mysqli_fetch_array($result);
echo $value['id']; // On this line i get the exact id that i want but if i try to echo this inside "if(mysqli_num_rows($result) == 1) { }" its like the value variable does not exist
if(mysqli_num_rows($result) == 1) {
session_start();
echo $value['id']=$_SESSION['id'];exit; // Getting this error -> "Notice: Undefined index: id"
header("Location: ./cpanel/#welcome");
}
【问题讨论】:
-
你的会话变量设置了吗?它可能指的是
$_SESSION的未定义索引,称为id。尝试print_r($_SESSION);进行检查。 -
0_*
mysql_real_escape_string结合与mysqli_*?严重地?你为什么不使用准备好的语句? -
我是个菜鸟,但我想尽可能多地学习,以便帮助我:b 那么,你建议我使用什么来与 mysqli 更兼容?
标签: php indexing mysqli echo undefined