webguync Posted September 28, 2009 Share Posted September 28, 2009 need to know why I am getting this error. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /products.php on line 15 here is the code <?php ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); $link = mysql_connect("localhost","username","password"); mysql_select_db("TESTING"); $query = 'SELECT * FROM Products'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<products>\n"; while ($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["product"] . "</item>\n"; } echo "</products>\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
eatfishy Posted September 28, 2009 Share Posted September 28, 2009 while ($line = mysql_fetch_assoc($results)) Shouldn't you be using == instead of = ? == is for comparing = is for storing Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted September 28, 2009 Share Posted September 28, 2009 while ($line = mysql_fetch_assoc($results)) Shouldn't you be using == instead of = ? No, because the OP is trying to store the value returned by mysql_fetch_assoc($results) in the $line variable, so he is correct to use assignment = rathe rthan comparison ==. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 28, 2009 Share Posted September 28, 2009 Hi webguync, The single = is the correct syntax for this query. Are you sure the 'Products' table exists? (With the capital P)? Also, are you sure you are connecting to the database? Amend your code to read: <?php ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); $link = mysql_connect("localhost","username","password") or trigger_error('Query failed: ' . mysql_error()); mysql_select_db("TESTING") or trigger_error('Query failed: ' . mysql_error()); $query = 'SELECT * FROM Products'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<products>\n"; while ($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["product"] . "</item>\n"; } echo "</products>\n"; mysql_close($link); ?> That way you will be able to whether your code is actually connecting and selecting the database. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted September 28, 2009 Share Posted September 28, 2009 need to know why I am getting this error. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /products.php on line 15 Generally it means that your SQL query has failed for some reason. Try doing $results = mysql_query($query) or die('ERROR: '.mysql_error().' in '.$query); Quote Link to comment Share on other sites More sharing options...
webguync Posted September 28, 2009 Author Share Posted September 28, 2009 it was a database connection issue. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.