Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


skidmark10

Recommended Posts

I've never encountered this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

Does anyone knows where it stems from, and ways to fix it?

 

Here's my code just in case.

 

$sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID=" .$_POST['clientid']. ""or die ('Error: '.mysql_error ());

$query = mysql_query($sql);

echo "<table border='0'>
<tr>
<th>Client ID</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
</tr>";

while ($row = mysql_fetch_array($sql));
   {
   echo "<tr>";
   echo "<td>" . $row['Client_ID'] . "</td>";
   echo "<td>" . $row['Slim_Slender'] . "</td>";
   echo "<td>" . $row['Average'] . "</td>";
   echo "<td>" . $row['Athletic'] . "</td>";
   echo "<td>" . $row['Heavy'] . "</td>";
   echo "</tr>";
   }
echo "</table>";

mysql_close($con);
?> 

please mark as solved. the topic solved button can be found at the bottom left of the page

 

I am still receiving the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource after making the corrections. Is there anything else I can do?

 

$sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID= " .$_POST['clientid']. "";

$query = mysql_query($sql);

echo "<table border='0'>
<tr>
<th>Client ID</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
<th>Partner's Body Type</th>
</tr>";

while ($row = mysql_fetch_array($query))
   {
   echo "<tr>";
   echo "<td>" . $row['Client_ID'] . "</td>";
   echo "<td>" . $row['Slim_Slender'] . "</td>";
   echo "<td>" . $row['Average'] . "</td>";
   echo "<td>" . $row['Athletic'] . "</td>";
   echo "<td>" . $row['Heavy'] . "</td>";
   echo "</tr>";
   }
echo "</table>";

mysql_close($con);
?> 

The query is failing for some reason, but you have no error-handling logic in place to catch that and report any errors. Is that all of the code, or is there more to it?

The query is failing for some reason, but you have no error-handling logic in place to catch that and report any errors. Is that all of the code, or is there more to it?

 

How can I put in the error-handling logic? :)

This is all of my php code (minus my database connection code), I'll post my html code so you can see the form.

 

HTML

<form name="input" action="fetchclientprofile.php" method="GET">
<center> Client ID <input type="text" name="clientid" /><br /> </center>
<center> <input type="submit" value="Retrieve" /> </center>

 

PHP

$sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID= " .$_POST['clientid']. "";

 

$query = mysql_query($sql);

 

echo "<table border='0'>

<tr>

<th>Client ID</th>

<th>Partner's Body Type</th>

<th>Partner's Body Type</th>

<th>Partner's Body Type</th>

<th>Partner's Body Type</th>

</tr>";

 

while ($row = mysql_fetch_array($query))

  {

  echo "<tr>";

  echo "<td>" . $row['Client_ID'] . "</td>";

  echo "<td>" . $row['Slim_Slender'] . "</td>";

  echo "<td>" . $row['Average'] . "</td>";

  echo "<td>" . $row['Athletic'] . "</td>";

  echo "<td>" . $row['Heavy'] . "</td>";

  echo "</tr>";

  }

echo "</table>";

 

mysql_close($con);

?>

Fixed it :)

 

Instead of

$sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID=" .$_POST['clientid']. ""or die ('Error: '.mysql_error ());

 

It should be

$sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID='$_POST[clientid]'"

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.