“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

后端 未结 28 945
盖世英雄少女心
盖世英雄少女心 2021-01-24 14:18

I\'m running a PHP script and continue to receive errors like:

Notice: Undefined variable: my_variable_name in C:\\wamp\\www\\mypath\\index.php on line 10

28条回答
  •  -上瘾入骨i
    2021-01-24 15:03

    Another reason why an undefined index notice will be thrown, would be that a column was omitted from a database query.

    I.e.:

    $query = "SELECT col1 FROM table WHERE col_x = ?";
    

    Then trying to access more columns/rows inside a loop.

    I.e.:

    print_r($row['col1']);
    print_r($row['col2']); // undefined index thrown
    

    or in a while loop:

    while( $row = fetching_function($query) ) {
    
        echo $row['col1'];
        echo "
    "; echo $row['col2']; // undefined index thrown echo "
    "; echo $row['col3']; // undefined index thrown }

    Something else that needs to be noted is that on a *NIX OS and Mac OS X, things are case-sensitive.

    Consult the followning Q&A's on Stack:

    • Are table names in MySQL case sensitive?

    • mysql case sensitive table names in queries

    • MySql - Case Sensitive issue of tables in different server

提交回复
热议问题