PHP mysqli 函数 return 值失败
PHP mysqli function return value failing
在此代码块中,它以前设计为使用 session_id。我正在尝试从使用 session_id 转换为使用从数据库检索到的用户 ID。我不确定我做错了什么,但函数没有返回变量。如有任何建议,我们将不胜感激。
protected function get_user_id() {
//previous code used the session id
//@session_start();
//return session_id();
// New code to use User ID instead of session_id
// Connecting to the database
include ("../../../admin/includes/connect.php");
// Let's get the user ID from the database for use with the widget
$user_id_query = "SELECT nonadmin_user_id FROM `nonadmin_user_login` WHERE email = '$_SESSION[email]'";
$run_query = mysqli_query($conn, $user_id_query);
while($row=mysqli_fetch_array($run_query)){
// Create variable for the user's id
$nonadmin_user_id = $row['nonadmin_user_id']; }
return $nonadmin_user_id;
}
// This function needs to use the variable $nonadmin_user_id
protected function get_user_path() {
if ($this->options['user_dirs']) {
return $this->get_user_id().'/';
}
return '';
}
"Fred you're the man! It was the session. I removed the comment out from in front of the session start and now it works perfect. What baffles me on this is I was under the impression that if you start a session in a file and then include other files the included files did not require the session to be started."
需要启动会话,以便在您的查询中识别并成功传递会话数组。
此外,session_start();
需要驻留在所有使用会话的文件中。
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
旁注:错误报告只应在试运行中进行,绝不能在生产中进行。
在此代码块中,它以前设计为使用 session_id。我正在尝试从使用 session_id 转换为使用从数据库检索到的用户 ID。我不确定我做错了什么,但函数没有返回变量。如有任何建议,我们将不胜感激。
protected function get_user_id() {
//previous code used the session id
//@session_start();
//return session_id();
// New code to use User ID instead of session_id
// Connecting to the database
include ("../../../admin/includes/connect.php");
// Let's get the user ID from the database for use with the widget
$user_id_query = "SELECT nonadmin_user_id FROM `nonadmin_user_login` WHERE email = '$_SESSION[email]'";
$run_query = mysqli_query($conn, $user_id_query);
while($row=mysqli_fetch_array($run_query)){
// Create variable for the user's id
$nonadmin_user_id = $row['nonadmin_user_id']; }
return $nonadmin_user_id;
}
// This function needs to use the variable $nonadmin_user_id
protected function get_user_path() {
if ($this->options['user_dirs']) {
return $this->get_user_id().'/';
}
return '';
}
"Fred you're the man! It was the session. I removed the comment out from in front of the session start and now it works perfect. What baffles me on this is I was under the impression that if you start a session in a file and then include other files the included files did not require the session to be started."
需要启动会话,以便在您的查询中识别并成功传递会话数组。
此外,session_start();
需要驻留在所有使用会话的文件中。
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
旁注:错误报告只应在试运行中进行,绝不能在生产中进行。