3

I am getting this error:

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; ?>

Can anyone help me understand (what is causing) this error?

J0e3gan
  • 8,570
  • 9
  • 52
  • 78
simplename
  • 75
  • 2
  • 7

1 Answers1

6

You're retrieving the database field kolebro using the alias full_name – so $session_data won't have a kolebro index, it'll have one called full_name instead.

  • Either change $session_data['kolebro'] to $session_data['full_name']
  • Or remove AS full_name from the MySQL query.

Also, please don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Shai
  • 6,724
  • 3
  • 16
  • 21