PHP未定义的偏移量:服务器日志中出现0错误.如何避免



我在Nginx服务器日志中收到标题错误。我检查了许多其他类似的问题,但都没有成功。php脚本按预期工作,但每次点击页面时都会出现错误。

以下是受影响的代码:

$user_slug=$_GET['user-id'];
$where = array("user_url"=>$user_slug);
$user_info = $operation->select_record('*',$where,'tbl_users');
$user_name =   $user_info[0]['user_name'];  
$user_email =   $user_info[0]['user_email']; 
$user_text =   $user_info[0]['user_text'];

相关功能(select_record(如下:

function select_record($tblfld,$where,$table){
$sql = "";
$condition = "";
foreach ($where as $key => $value) {
$condition .= $key . "='" . $value . "' AND ";
}
$condition = substr($condition, 0, -5);
$sql .= "SELECT ".$tblfld." FROM ".$table." WHERE ".$condition;
$smt = $this->conn->prepare($sql);
$smt->execute();
return $smt->fetchAll();
}

我非常感谢你在这方面的帮助。

在访问之前检查结果数组。。

$user_slug=$_GET['user-id'];
$where = array("user_url"=>$user_slug);
$user_info = $operation->select_record('*',$where,'tbl_users');
if (!empty($user_info)) {
$user_name =   $user_info[0]['user_name'];  
$user_email =   $user_info[0]['user_email']; 
$user_text =   $user_info[0]['user_text'];
}

最新更新