I am getting this PHP error, what does it mean?
Notice: Undefined offset: 0 in
C:\\xampp\\htdocs\\mywebsite\\reddit_vote_tut\\src\\votes.php on line 41
If you leave out the brackets then PHP will assign the keys by default.
Try this:
$votes = $row['votes_up'];
$votes = $row['votes_down'];
In my case it was a simple type
$_SESSION['role' == 'ge']
I was missing the correct closing bracket
$_SESSION['role'] == 'ge'
getAllVotes()
isn't returning an array with the indexes 0
or 1
. Make sure it's returning the data you want by calling var_dump() on the result.
Use mysql row instead
mysql_fetch_row($r)
Meanwhile consider using mysqli or PDO
?>
its just a warning use:
error_reporting(0);
it shows when we do not initialize array and direct assigning value to indexes.
somefunction{
$raja[0]="this";
$raja[1]="that";
}
instead :
somefunction{
$raja=array(0=>'this',1='that');
//or
$raja=array("this","that");
}
it just notification, do not generate any output error or any unexpected output.
Use print_r($votes);
to inspect the array $votes
, you will see that key 0
does not exist there. It will return NULL and throw that error.