By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Notice: Undefined index: Error

P: n/a
I am looking for some help if anyone can lend a hand.

I have a simple php website that displays a table from my mysql
database.

To prep for my MCSE I moved my home server to Windows 2003 Standard, I
installed mysql and php 5 to run some of my databases and websites.

Under Linux the site worked fine, under windows I keep getting Notice
Undefined Index error on line 67

I have went back to the basics just pull the data then display and
still get the same error.

60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
61
62 $result = mysql_query($sql, $dbcnx) or die(mysql_error());
63 $number_of_rows = mysql_num_rows($result);
64
65 while ($newArray = mysql_fetch_array($result)) {
66
67 $id = $newArray['id'];
68 $testField = $newArray['testField'];
69
70 echo "The ID is $id and the text is $testField <br>";
Anyone have any thoughts?

Apr 25 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
js********@gmail.com wrote:
I am looking for some help if anyone can lend a hand.

I have a simple php website that displays a table from my mysql
database.

To prep for my MCSE I moved my home server to Windows 2003 Standard, I
installed mysql and php 5 to run some of my databases and websites.

Under Linux the site worked fine, under windows I keep getting Notice
Undefined Index error on line 67

I have went back to the basics just pull the data then display and
still get the same error.

60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
61
62 $result = mysql_query($sql, $dbcnx) or die(mysql_error());
63 $number_of_rows = mysql_num_rows($result);
64
65 while ($newArray = mysql_fetch_array($result)) {
66
67 $id = $newArray['id'];
^^
id, without a $, is a constant. Yet you probably haven't defined that in
your code prior to using it. (I suspect this is a typo though, yes?)
If you have error reporting set to E_ALL, besides warnings and errors,
you'll get notices as well.

HTH

Sh.

Apr 25 '07 #2

P: n/a
Schraalhans Keukenmeester wrote:
js********@gmail.com wrote:
>I am looking for some help if anyone can lend a hand.

I have a simple php website that displays a table from my mysql
database.

To prep for my MCSE I moved my home server to Windows 2003 Standard, I
installed mysql and php 5 to run some of my databases and websites.

Under Linux the site worked fine, under windows I keep getting Notice
Undefined Index error on line 67

I have went back to the basics just pull the data then display and
still get the same error.

60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
61
62 $result = mysql_query($sql, $dbcnx) or die(mysql_error());
63 $number_of_rows = mysql_num_rows($result);
64
65 while ($newArray = mysql_fetch_array($result)) {
66
67 $id = $newArray['id'];
^^
id, without a $, is a constant. Yet you probably haven't defined that in
your code prior to using it. (I suspect this is a typo though, yes?)
If you have error reporting set to E_ALL, besides warnings and errors,
you'll get notices as well.

HTH

Sh.
Skip that, I'm not awake yet.
Is 'id' a valid field in your db?
Try var_dump($newArray) to see what is returned from the db.
Apr 25 '07 #3

P: n/a
<js********@gmail.comwrote in message
news:11**********************@r35g2000prh.googlegr oups.com...
63 $number_of_rows = mysql_num_rows($result);
64
65 while ($newArray = mysql_fetch_array($result)) {
You are certain that "id" is the field name?
If so you could try,
mysql_fetch_array($result, MYSQL_ASSOC)) .
66
67 $id = $newArray['id'];
68 $testField = $newArray['testField'];
69
70 echo "The ID is $id and the text is $testField <br>";
Anyone have any thoughts?
Vince
Apr 25 '07 #4

P: n/a
65 while ($newArray = mysql_fetch_array($result)) {
67 $id = $newArray['id'];
68 $testField = $newArray['testField'];
You should use fetch_assoc() if the index is a string ('id') rather than
a number(0,1,2,3...).

--
iTech Consulting Services Limited
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Apr 25 '07 #5

P: n/a
js********@gmail.com wrote:
I am looking for some help if anyone can lend a hand.

I have a simple php website that displays a table from my mysql
database.

To prep for my MCSE I moved my home server to Windows 2003 Standard, I
installed mysql and php 5 to run some of my databases and websites.

Under Linux the site worked fine, under windows I keep getting Notice
Undefined Index error on line 67

I have went back to the basics just pull the data then display and
still get the same error.

60 $sql = "SELECT * from newschool ORDER BY State, CollNam";
61
62 $result = mysql_query($sql, $dbcnx) or die(mysql_error());
63 $number_of_rows = mysql_num_rows($result);
64
65 while ($newArray = mysql_fetch_array($result)) {
66
67 $id = $newArray['id'];
68 $testField = $newArray['testField'];
69
70 echo "The ID is $id and the text is $testField <br>";
Anyone have any thoughts?
Don't worry about those who are telling you to use mysql_fetch_assoc().
Your code is just fine; the default for mysql_fetch_array() is to
fetch both numeric and associative indicies. It may just be a little
slower than mysql_fetch_assoc(), but you'll never notice the difference.

As for your problem - it looks like you don't have a column named 'id'
in the `newschool` table. Perhaps when you created the database here
you named it something else (or had a finger check)?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 25 '07 #6

P: n/a
Don't worry about those who are telling you to use mysql_fetch_assoc().
Your code is just fine; the default for mysql_fetch_array() is to fetch
both numeric and associative indicies. It may just be a little slower
Thank you.

--
iTech Consulting Services Limited
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Apr 26 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.