Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given


Recommended Posts

Please can someone fix this code below

 

<?php include("function.php"); ?> <?php include("header.php"); ?> <?php include("headscript.php"); ?> <script type="text/javascript"> function noAcc(){ $.fallr('show', { icon : 'error', content : '<p>You need an account to complete offers. Don\'t you want us to track the points you earn!? <br>;)</p>' }); }; </script> <script type="text/javascript"> function errorMsg(msg){ $.fallr('show', { icon : 'error', content : msg }); }; </script> <div id="body"> <div class="box"> <h2>Rewards</h2> <div style="padding:10px; border:1px solid #557453; background:url(../images/boxbg.png);"> <table align="center"> <?php $rewards = mysql_query("SELECT * FROM rewards ORDER BY points"); $rowNum = 0; $rowMax = 4; while($row = mysql_fetch_array($rewards)) { if($rowNum ==0){ echo "<tr>"; } echo "<td style=\"border:1px solid #557453;\" align=\"center\" width=\"200px\"><h3 style=\"background:url(../images/historytop.png);\">". $row['title']."</h3><img style=\"margin:5px;\" src=\"". $row['img']."\" width=\"150\" height=\"150\" /><br /><table width=\"100%\"><tr><td valign=\"middle\"><h4 style=\"display:inline\">Points:</h4> ". $row['points']." <img src=\"images/point.png\" /></td>"; if(!isset($_SESSION["user"])){ echo"<td valign=\"middle\"><img onclick=\"errorMsg('You need an account to be able to purchase items.')\" style=\"cursor:pointer; border:0px\" src=\"/images/purchase.png\" /></td> </tr></table></td>"; } else { $userId = $_SESSION["user"]; $myPoints = mysql_result(mysql_query("SELECT points FROM balances WHERE userId = '$userId'"), 0); if($myPoints <= $row['points']){ echo"<td valign=\"middle\"><img onclick=\"errorMsg('You do not have enough points to get that. You have $myPoints points.')\" style=\"cursor:pointer; border:0px\" src=\"/images/purchase.png\" /></td> </tr></table></td>"; } else { echo"<td valign=\"middle\"><a href=\"redeem.php?id=".$row['rewardId']."\"><img border:0px\" src=\"/images/purchase.png\" /></a></td> </tr></table></td>"; } } $rowNum++; if($rowNum >= $rowMax){ $rowNum = 0; echo "</tr>"; } } ?> </table> </div> </div> <div class="clear"></div> </div> </div> <?php include("footer.php"); ?> </body> </html>

Basically you query is failing and is not returning a result resource (this what mysql_fetch_assoc requires, hense the error message).

 

The solution is to add error checking tn your code. You will find many topics discussing this exact issue if you search your error message on this forum.

You have two mysql queries in that bit of code, first job is to find out which one is failing. The first one looks pretty general, so my guess is that it's the second one, and there is nothing in the balances table where  userId = '$userId'.

 

You need to see what request is being made. One suggestion could be to squeeze in a line of code 

echo "SELECT points FROM balances WHERE userId = '$userId'";

just after that second mysql query and post back on here what comes up.

Basically you query is failing and is not returning a result resource (this what mysql_fetch_assoc requires, hense the error message).

 

The solution is to add error checking tn your code. You will find many topics discussing this exact issue if you search your error message on this forum.

 

There's even a sticky note  :happy-04::

http://forums.phpfreaks.com/topic/273121-readme-php-resources-faqs/?do=findComment&comment=1428660

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.