I get this array from a function (var_dump()):
...{ [0]=> string(7) "user_id" } [1]=> array(1) { [0]=> string(7) "user_id" } [2]...
When I try to separate the values with:
$var2 = $var[‘user_id’]
I get the error “undefined index ‘user_id'”, even though, as you can see, the name of the value is “user_id”, and I’ve checked my database a hundred times, and that IS the name of the index.
What other possible sources of error are there?
I appreciate any help!
Thank you in advance!
function get_subscribitions($user)
{
$user = mysql_real_escape_string ($user);
$sql = "SELECT * FROM `subscribe` WHERE subscriber = '$user'";
$result = mysql_query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
mysql_free_result($result);
return $rows;
Can anyone pinpoint where in the above code, I make the mistake leading to this problem?
Thanks.
The array key 0 contains a string called
'user_id'but there is no key named'user_id', hence why you’re getting the error.I suggest you take a look at how you’re compiling this data (query results perhaps?).