php\sql error

Reply

Join Date: Nov 2007
Posts: 4
Reputation: emarkus is an unknown quantity at this point 
Solved Threads: 0
emarkus emarkus is offline Offline
Newbie Poster

php\sql error

 
0
  #1
Feb 23rd, 2008
Hi I am trying to teach myself some php and get this error (below) when I query a sql database this is just a tutorial and will never go live.

I have hilighted the area in bold where the unseen error is.

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14


[code]
<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "password";
$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);

$sql = "SELECT * FROM products";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
echo $row['product'];

}

?>
[code/]

please go easy on me as am a novice...
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: squid44th is an unknown quantity at this point 
Solved Threads: 0
squid44th's Avatar
squid44th squid44th is offline Offline
Newbie Poster

Re: php\sql error

 
1
  #2
Feb 23rd, 2008
I would use mysql_fetch_array instead of mysql_fetch_assoc.

But your problem lies here:

mysql_select_db ($dbdatabase, $db);
Last edited by squid44th; Feb 23rd, 2008 at 11:50 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 4
Reputation: emarkus is an unknown quantity at this point 
Solved Threads: 0
emarkus emarkus is offline Offline
Newbie Poster

Re: php\sql error

 
0
  #3
Feb 23rd, 2008
thanks so simple but just could not see it, its been driving me crazy.......

cant believe i could see that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 593 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC