Notice: Undefined offset: 0 in

后端 未结 14 1550
太阳男子
太阳男子 2020-11-28 11:05

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


        
相关标签:
14条回答
  • 2020-11-28 11:18

    If you leave out the brackets then PHP will assign the keys by default.

    Try this:

    $votes = $row['votes_up']; 
    $votes = $row['votes_down']; 
    
    0 讨论(0)
  • 2020-11-28 11:18

    In my case it was a simple type

    $_SESSION['role' == 'ge']
    

    I was missing the correct closing bracket

    $_SESSION['role'] == 'ge'
    
    0 讨论(0)
  • 2020-11-28 11:19

    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.

    0 讨论(0)
  • 2020-11-28 11:20

    Use mysql row instead

    mysql_fetch_row($r)

    Meanwhile consider using mysqli or PDO

    ?>

    0 讨论(0)
  • 2020-11-28 11:20

    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.

    0 讨论(0)
  • 2020-11-28 11:25

    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.

    0 讨论(0)
提交回复
热议问题