General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 26th, 2002, 07:10 PM
CoconutF7 CoconutF7 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Hawkesbury, Ontario
Posts: 10 CoconutF7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Notice: Use of undefined constant

Hi,

I read the tutorial at http://www.devarticles.com/content....cleId=23&page=4 and I have some error message.
Notice: Use of undefined constant name
and Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp\www\test.php on line 6
Sorry, no records were found! How to fix this? I'm using php4.2.2


PHP Code:
<html
<
body
<?
PHP $db = @mysql_connect("localhost""root"); 
mysql_select_db("mydb",$db); 
$result mysql_query("SELECT * FROM address",$db); 

if (
$myrow mysql_fetch_array($result)) 

echo 
"<table border=1>\n"
echo 
"<tr><td>Name</td><td>Address</td><td>Home Number</td><td>Work Number</td></tr>\n"
do { 
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n"$myrow[name], $myrow[address], $myrow[hnum],$myrow[wnum]); 

while (
$myrow mysql_fetch_array($result)); 
echo 
"</table>\n"

else { 
echo 
"Sorry, no records were found!"

?> 
</body> 
</html> 

Reply With Quote
  #2  
Old August 26th, 2002, 07:47 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Firstly do you have the database name as 'mydb'?? and do you have the table structures set up?

Reply With Quote
  #3  
Old August 26th, 2002, 08:19 PM
CoconutF7 CoconutF7 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Hawkesbury, Ontario
Posts: 10 CoconutF7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I have the table but I changed the name of my db for this forum.
The name of my db is mydomain_com
and this is the table:

Everything is working but not for this lesson.
CREATE TABLE address (
id tinyint(4) NOT NULL auto_increment,
name varchar(50) default NULL,
address varchar(225) default NULL,
hnum varchar(10) default NULL,
wnum varchar(10) default NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
)

INSERT INTO address VALUES (1, 'James Red', '3 Not Here Cres, Hopeville', '555-4123', '555-9777');
INSERT INTO address VALUES (2, 'John Back', '8 nice Place, Lo', '555-7894', '555-3131');
INSERT INTO address VALUES (3, 'Brad Feed', '7 victor pl, Moronville', '555-1919', '555-9764');

Reply With Quote
  #4  
Old August 26th, 2002, 11:24 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
well the, if you change the database to 'mydomain_com' then you need to tell the php script of the changes otherwise it will look for the other database name and give you errors like you have now

mysql_select_db("mydb",$db);

needs to be

mysql_select_db("mydomain_com",$db);

Reply With Quote
  #5  
Old August 27th, 2002, 01:28 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
The problem is on this line:

printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow[name], $myrow[address], $myrow[hnum],$myrow[wnum]);

See those arrays? They should be $myrow['name'], $myrow['address'] and so on.. if they don't have the '' around them, it still works, but php thinks they are constants
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #6  
Old August 27th, 2002, 02:52 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
ahhh yes that would help, but his problem is the mysql error, which would be cause by looking at the wrong database

Reply With Quote
  #7  
Old August 27th, 2002, 06:04 AM
newgent newgent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 12 newgent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey I think Both Lindset and Ben have given the answer !!

Reply With Quote
  #8  
Old August 27th, 2002, 10:55 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
In case this helps, I'm not sure why you have this:

UNIQUE KEY id (id)
)


Remove the first "id".
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #9  
Old August 27th, 2002, 12:17 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
I don't think he needs the UNIQUE KEY at all, because a PRIMARY KEY is always a unique key

Reply With Quote
  #10  
Old August 27th, 2002, 10:58 PM
CoconutF7 CoconutF7 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Hawkesbury, Ontario
Posts: 10 CoconutF7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I changed $myrow['name'], $myrow['address'] and everything is working now

Thanks!

Reply With Quote
  #11  
Old August 28th, 2002, 08:05 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Quote:
Originally posted by Lindset
I don't think he needs the UNIQUE KEY at all, because a PRIMARY KEY is always a unique key


That too... but I meant to remove the duplicate 'id'...

As long as he got it working!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Notice: Use of undefined constant


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT