我收到此错误:
Notice: Undefined index: kolebro in /Applications/MAMP/htdocs/includes.php on line 12
function.php
public function User_Details($uid)
{
$username = mysql_real_escape_string($uid);
$query = mysql_query("SELECT uid, username, sansiti, kolebro AS full_name FROM users WHERE uid = '$uid' AND status = '1'") or die(mysql_error());
$data = mysql_fetch_array($query);
return $data;
}
includes.php
$session_data = $Wall->User_Details($uid);
$session_sansiti = $session_data['sansiti']; // <== Line 12
$session_kolebro = $session_data['kolebro'];
的index.php
<?php echo $session_kolebro; ?>
<?php echo $session_sansiti; ?>
任何人都可以帮助我理解(导致什么)这个错误吗?
答案 0 :(得分:6)
您正在使用别名kolebro
检索数据库字段full_name
,因此$session_data
不会拥有kolebro
索引,而是{&#39}。将有一个名为full_name
的人。
$session_data['kolebro']
更改为$session_data['full_name']
AS full_name
。此外,please don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。