|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
|
|
#2
|
|||
|
|||
|
Firstly do you have the database name as 'mydb'?? and do you have the table structures set up?
|
|
#3
|
|||
|
|||
|
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'); |
|
#4
|
|||
|
|||
|
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); |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
ahhh yes that would help, but his problem is the mysql error, which would be cause by looking at the wrong database
|
|
#7
|
|||
|
|||
|
Hey I think Both Lindset and Ben have given the answer !!
![]() |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
|||
|
|||
|
I don't think he needs the UNIQUE KEY at all, because a PRIMARY KEY is always a unique key
|
|
#10
|
|||
|
|||
|
Hi,
I changed $myrow['name'], $myrow['address'] and everything is working now Thanks! |
|
#11
|
|||
|
|||
|
Quote:
That too... but I meant to remove the duplicate 'id'... As long as he got it working! ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Notice: Use of undefined constant |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|