Warptweet Posted March 22, 2007 Share Posted March 22, 2007 This is my simple database connecting code, which returns rows that match. ERROR: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/warp/public_html/gm/index.php on line 456. I put a comment in there noting where line 456 is. CODE: if ($_GET['category'] == 'actiongame'){ $con = mysql_connect("localhost","warp_gm","Forest77"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Forest77", $con); $result = mysql_query("SELECT * FROM accepted_uploads WHERE uploadgenre='Action Game' ORDER BY uploadid"); echo "<tr> <th>Name</th> <th>Author</th> <th>Genre</th> <th>Style</th> </tr>"; while($row = mysql_fetch_array($result)) // THIS IS LINE 456 { echo "<tr>"; echo "<td><a href=\"?cmd=viewflash&id=" . $row['uploadid'] . ">" . $row['uploadname'] . "</td>"; echo "<td>" . $row['uploadauthor'] . "</td>"; echo "<td>" . $row['uploadgenre'] . "</td>"; echo "<td>" . $row['uploadstyle'] . "</td>"; echo "</tr>"; } mysql_close($con); } Link to comment https://forums.phpfreaks.com/topic/43851-another-error/ Share on other sites More sharing options...
Warptweet Posted March 22, 2007 Author Share Posted March 22, 2007 Please people, I really need help! Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213109 Share on other sites More sharing options...
fert Posted March 22, 2007 Share Posted March 22, 2007 change $result = mysql_query("SELECT * FROM accepted_uploads WHERE uploadgenre='Action Game' ORDER BY uploadid"); to $result = mysql_query("SELECT * FROM accepted_uploads WHERE uploadgenre='Action Game' ORDER BY uploadid") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213111 Share on other sites More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 if ($_GET['category'] == 'actiongame'){ $con = mysql_connect("localhost","warp_gm","Forest77"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Forest77", $con); $result = mysql_query("SELECT * FROM accepted_uploads WHERE uploadgenre='Action Game' ORDER BY uploadid"); $num = mysql_affected_rows($result); if ($num > 0) { echo "<tr> <th>Name</th> <th>Author</th> <th>Genre</th> <th>Style</th> </tr>"; while($row = mysql_fetch_array($result)) // THIS IS LINE 456 { echo "<tr>"; echo "<td><a href=\"?cmd=viewflash&id=" . $row['uploadid'] . ">" . $row['uploadname'] . "</td>"; echo "<td>" . $row['uploadauthor'] . "</td>"; echo "<td>" . $row['uploadgenre'] . "</td>"; echo "<td>" . $row['uploadstyle'] . "</td>"; echo "</tr>"; } } else { echo "Query found no results."; } mysql_close($con); } Run this code in it's place. I've added in a check to see if the query is actually finding results. If there are no results and you try to fetch them in an array, it will return an error. Let me know what happens. Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213112 Share on other sites More sharing options...
fert Posted March 22, 2007 Share Posted March 22, 2007 If there are no results and you try to fetch them in an array, it will return an error No, that's not what will happen. you just won't get anything on the page Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213113 Share on other sites More sharing options...
trq Posted March 22, 2007 Share Posted March 22, 2007 I've added in a check to see if the query is actually finding results. You need to use mysql_num_rows not mysql_affected_rows. mysql_affected_rows is only usefull with INSERT, DELETE and UPDATE statements. Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213114 Share on other sites More sharing options...
per1os Posted March 22, 2007 Share Posted March 22, 2007 Anyhow like fert said, it just won't display anything on the page. It should still return a valid result as long as the query ran. After you add the OR DIE that will tell you if your query had an error on it. Although it is good to check via mysql_num_rows to make sure, it is not necessary. Link to comment https://forums.phpfreaks.com/topic/43851-another-error/#findComment-213130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.