Undefined Offset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • delusion7
    New Member
    • Sep 2006
    • 37

    Undefined Offset

    I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\Up dateContactInfo .php on line 36"
    this is the code I am recieving the error on:
    [PHP]if (mysqli_num_row s($QueryResult) > 0) {
    $Row = mysqli_fetch_ro w($QueryResult) ;
    $First = stripslashes($R ow[3]);
    $Last = stripslashes($R ow[4]);
    $Phone = stripslashes($R ow[5]);
    $Address = stripslashes($R ow[6]);
    $City = stripslashes($R ow[7]);
    $State = stripslashes($R ow[8]);
    $Zip = stripslashes($R ow[9]);
    mysqli_free_res ult($QueryResul t);
    [/PHP]
    My array has 9 elements, everytime I change the indexes listed above to 1 less, assuming zero-based array, the data that is in $First name is displayed in the $Last name field. Please help!!
    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    When your $row has 9 elements, the first one is $Row[0] and the last one is $Row[8], so $Row[9] is outside the range.

    Ronald :cool:

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by delusion7
      My array has 9 elements, everytime I change the indexes listed above to 1 less, assuming zero-based array, the data that is in $First name is displayed in the $Last name field. Please help!!
      Thanks
      Check your database and SQL if that is the case. Your array is zero-based. row[3] will be the fourth field.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        I suppose you did a SELECT * in your query. Who gave you the quarantee that the sequence of the columns in your table would be identical to the order you created them in? If you want them in a specific order, issue a SELECT col1, col2, .... etc. Same applies to row sequence.

        It usually is so, but MySQL gives no guarantee at all, they even deny it, that it is. Remember, the whole point of a relational setup is to decouple data storage and presentation.

        See also this post about that same subject.

        Ronald :cool:

        Comment

        Working...