【发布时间】:2015-12-15 02:29:20
【问题描述】:
我使用$_SESSION['']; 在用户登录后从他们那里获取值。这些数据来自users 表。
我正在尝试
`SELECT *` `FROM roster`
当用户 API=$API 时,通过查询并为每个值分配一个 var
我可以通过以下方式做到这一点:
error_reporting(E_ALL);
include ('database_connection.php');
$API = $_SESSION['API'];
if ($API !== false) {
$roster_query = "SELECT * FROM roster WHERE API='$API'";
$result = mysqli_fetch_array(mysqli_query($dbc, $roster_query));
/* ROSTERS TABLE */
$StreetName = $result['streetname'];
$HouseNum = $result['housenumber'];
$City = $result['city'];
$State = $result['state'];
$Zipcode = $result['zipcode'];
/* SESSION */
$FirstName = $_SESSION['firstname'];
$LastName = $_SESSION['lastname'];
$Email = $_SESSION['email'];
/* this->$vars - Specific for this form */
$ExecutionDate = date("Y:M:D");
$DOCSIGNEDBYIP = $_SERVER['REMOTE_ADDR'];
}
但是,当我这样做时,会出现以下错误。如果我删除上面的代码没有错误,等等。
现在这并没有“破坏”我的代码,但我不想把它扫到地毯下并稍后解决。
谁能确定我哪里出错了?
警告:在第 48 行的 /home/.../public_html/.../.../.../db.php 中从空值创建默认对象
第 48 行: $return->$i = $row;
if(!$return_array) {
while($row = mysql_fetch_object($sql_query)) {
$return->$i = $row;
$i++;
}
严格标准: 不应静态调用非静态方法 Access::is_logged(),假设 $this 来自 /home/.../public_html/.../ 中的不兼容上下文。 ../.../APP.php 第 64 行
pinAPP 第 64 行: return Access::is_logged();
public function is_logged()
{
return Access::is_logged();
}
is_logged();
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php');
class pinAPP {
public function is_logged() {
return Access::is_logged();
}
}
访问
<?php
class Access {
private static $auth = false;
final public function is_logged( $require_admin_access = false ) {
if ( ! isset($_SESSION[LOGINSESSION]) )
return false;
self::$auth = true;
if ( $require_admin_access ) {
$u = new User();
if ( ! $u->is_admin() )
new Redirect(DEFAULT_RETURN_URL);
}
return self::$auth;
}
}
【问题讨论】:
-
如果在循环之前执行
$return = new stdClass();,则应该解析第 48 行。试试看。 -
然后在
Access类下,看is_logged()是否声明static function is_logged()用作Access::is_logged()。 -
你介意发布一个描述更多细节的答案@Rasclatt
标签: php