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); ?> Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/ 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 Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/#findComment-926442 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 ==. Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/#findComment-926457 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. Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/#findComment-926459 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); Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/#findComment-926461 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. Link to comment https://forums.phpfreaks.com/topic/175806-please-help-with-error/#findComment-926474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.