469,086 Members | 1,125 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

Undefined Offset

I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\UpdateContactInfo.php on line 36"
this is the code I am recieving the error on:
[PHP]if (mysqli_num_rows($QueryResult) > 0) {
$Row = mysqli_fetch_row($QueryResult);
$First = stripslashes($Row[3]);
$Last = stripslashes($Row[4]);
$Phone = stripslashes($Row[5]);
$Address = stripslashes($Row[6]);
$City = stripslashes($Row[7]);
$State = stripslashes($Row[8]);
$Zip = stripslashes($Row[9]);
mysqli_free_result($QueryResult);
[/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
Jan 6 '07 #1
3 3016
ronverdonk
4,258 Expert 4TB
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:
Jan 6 '07 #2
acoder
16,027 Expert Mod 8TB
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.
Jan 6 '07 #3
ronverdonk
4,258 Expert 4TB
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:
Jan 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by lawrence | last post: by
2 posts views Thread by Steven | last post: by
4 posts views Thread by Richard Lawrence | last post: by
9 posts views Thread by simple12 | last post: by
2 posts views Thread by neridaj | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.