Jump to content

Another Error :(


Warptweet

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.