mushfik Posted February 17, 2015 Share Posted February 17, 2015 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> Quote Link to comment https://forums.phpfreaks.com/topic/294661-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
Ch0cu3r Posted February 17, 2015 Share Posted February 17, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/294661-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1505883 Share on other sites More sharing options...
grissom Posted February 17, 2015 Share Posted February 17, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/294661-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1505891 Share on other sites More sharing options...
cyberRobot Posted February 17, 2015 Share Posted February 17, 2015 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 : http://forums.phpfreaks.com/topic/273121-readme-php-resources-faqs/?do=findComment&comment=1428660 Quote Link to comment https://forums.phpfreaks.com/topic/294661-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1505903 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.