skidmark10 Posted July 31, 2011 Share Posted July 31, 2011 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); ?> Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted July 31, 2011 Share Posted July 31, 2011 I'm not sure but I do see 2 double quotes here.. $sql = "SELECT * FROM `Partners_Body_Types` WHERE Client_ID=" .$_POST['clientid']. ""or die ('Error: '.mysql_error ()); Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 31, 2011 Share Posted July 31, 2011 This while ($row = mysql_fetch_array($sql)); Should be this while ($row = mysql_fetch_array($query)); Quote Link to comment Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 yours while ($row = mysql_fetch_array($sql)); remove ' ;' while ($row = mysql_fetch_array($sql)) { } Quote Link to comment Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 please mark as solved. the topic solved button can be found at the bottom left of the page Quote Link to comment Share on other sites More sharing options...
skidmark10 Posted July 31, 2011 Author Share Posted July 31, 2011 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); ?> Quote Link to comment Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 case sensitive issue check your table name and check the query Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2011 Share Posted July 31, 2011 please mark as solved. the topic solved button can be found at the bottom left of the page What if it isn't solved? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2011 Share Posted July 31, 2011 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? Quote Link to comment Share on other sites More sharing options...
skidmark10 Posted July 31, 2011 Author Share Posted July 31, 2011 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); ?> Quote Link to comment Share on other sites More sharing options...
skidmark10 Posted July 31, 2011 Author Share Posted July 31, 2011 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]'" 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.