Hello. Please look at the code below and tell me the correct code for it please. here is the message i get.."Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given"

<?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>
Member Avatar for diafol

Ok, I'll be as tactful as possible here as this is your first post. Please format and indent your code/markup properly and repost. It's an absolute mess and very very hard to follow.

It's unfortunate that you have javascript, HTML and PHP all mixed up. It's much easier if you separate these as much as possible.

Try to place most of the PHP above the !doctype declaration. JS scripts can usually be placed out of the way right at the bottom of the document, above the closing </body> tag.

BTW mysql_* functions have been deprecated. Do not use them. Use mysqli or PDO instead. Some of us won't touch these functions with a barge pole nor provide helpful answers for them.

I don't know how to do any of these would you not be able to find the main line which is causing problem and solve it for me. I would really appreciate it sir

Member Avatar for diafol

Sorry Mushfik, but as I stated, your code and markup is a complete mess. UNtil you tidy it up, I'm not going to look at it. I assume that will be true for other contributors too.

I tried as much as possible to remove otHer things. Please look at it

<?php
              $rewards = mysql_query("SELECT * FROM rewards ORDER BY points");
              $rowNum = 0;
              $rowMax = 4;
              while($row = mysql_fetch_array($rewards))
  {
      if($rowNum ==0){
          echo "....";
      }
      echo "..." align=\"center\" width=\"200px\"><h3 style=\"background:url(../images/historytop.png);\">". $row['title']. $row['img'].
      if(!isset($_SESSION["user"])){
      echo"....."
      } else {
          $userId = $_SESSION["user"];
          $myPoints = mysql_result(mysql_query("SELECT points FROM balances WHERE userId = '$userId'"), 0);
          if($myPoints <=  $row['points']){
              echo"..."
          } else {
                          echo"..."
          }
      }
      $rowNum++;
      if($rowNum >= $rowMax){
        $rowNum = 0;
        echo "</tr>";  
      }
  }
              ?>
Member Avatar for diafol

Ok, looks better. You may get more bites now.

Please i cannot try any better. Please look at the code and see if you can find the problem for me.

<?php
              $rewards = mysql_query("SELECT * FROM rewards ORDER BY points");
              $rowNum = 0;
              $rowMax = 4;
              while($row = mysql_fetch_array($rewards))
  {
      if($rowNum ==0){
          echo "....";
      }
      echo "..."
      if(!isset($_SESSION["user"])){
      echo"....."
      } else {
          $userId = $_SESSION["user"];
          $myPoints = mysql_result(mysql_query("SELECT points FROM balances WHERE userId = '$userId'"), 0);
          if($myPoints <=  $row['points']){
              echo"..."
          } else {
                          echo"..."
          }
      }
      $rowNum++;
      if($rowNum >= $rowMax){
        $rowNum = 0;
        echo "</tr>";  
      }
  }
              ?>
Member Avatar for diafol

Sorry I've stopped looking at mysql_* functions as it just feeds their use. However, other contributors will now be able to follow your code more easily.

Where is your connection? Check for errors to find the issue.

$rewards = mysql_query("SELECT * FROM rewards ORDER BY points") or die(mysql_error());
commented: good luck with this one +15

I have separate php code for connection details and linked in this script with php include. So I have got that. I will try this and will let you know

<?php include("function.php"); ?>
<?php include("header.php"); ?>
    <?php include("headscript.php"); ?>
    </div>
  </div>
  <div id="body">
    <div class="box">
        <?php
        if(isset($_SESSION["user"])){
        if(isset($_GET['id'])){ 
            $rewardId = mysql_real_escape_string($_GET['id']);
            $userId = $_SESSION["user"];
             $myPoints = mysql_result(mysql_query("SELECT points FROM balances WHERE userId = '$userId'"), 0);
             $rewardPoints = mysql_result(mysql_query("SELECT points FROM rewards WHERE rewardId = '$rewardId'"), 0);
             if($rewardPoints > $myPoints) {
                echo  "<h2>Redeem Failed!</h2><p>Don't have enough points to make the purchase.  Please go to the Rewards Page and look for a cheaper item.</p>";
             } else {
                  $reward = mysql_query("SELECT * FROM rewards WHERE rewardId = $rewardId");
                 echo "<h2>Confirm Order!</h2>";
                 echo "......."
                 while($row = mysql_fetch_array($rewards))
  {
      echo "<h3>".$row['title']."</h3> <img style=\"margin:5px;\" src=\"". $row['img']."\" width=\"150\" height=\"150\" /><br />" .$row['desc']. "<br><h4 style=\"display:inline\">Current Points:</h4> $myPoints <img src=\"images/point.png\" /><br> <h4 style=\"display:inline\">Points:</h4> ". $row['points']." <img src=\"images/point.png\" /><br> <h4 style=\"display:inline\">Points After:</h4> ". ($myPoints - $row['points'])." <img src=\"images/point.png\" /><br><br>";

      echo "<form id=\"orderForm\" action=\"order.php\" method=\"post\"> 
      <input type=\"hidden\"
      name=\"userId\" 
      value=\"$userId\"
      >
          <input type=\"hidden\"
      name=\"rewardId\" 
      value=\"$rewardId\"
      >
          <input type=\"hidden\"
      name=\"rewardTitle\" 
      value=\"".$row['title']."\"
      >
      ";
      if($row['type'] == "email"){
          echo "<input type=\"hidden\"
      name=\"type\" 
      value=\"email\"
      >";
          $userEmail = mysql_result(mysql_query("SELECT email FROM users WHERE userId = '$userId'"), 0);
        echo "<div class=\"box contactbox\"><h3 style='display:inline;'>Where To Send...</h3><label><h4>Email To:</h4><input name=\"sendto\" value=\"$userEmail\" type=\"text\"></label></div>";
      } else if($row['type'] == "ship"){
                  echo "<input type=\"hidden\"
      name=\"type\" 
      value=\"ship\"
      >";
          $userEmail = mysql_result(mysql_query("SELECT email FROM users WHERE userId = '$userId'"), 0);
        echo "<div class=\"box contactbox\"><h3 style='display:inline;'>Where To Send...</h3><label><h4>Street Address:</h4><input name=\"street\" value=\"\" type=\"text\"></label><label><h4>City:</h4><input name=\"city\" value=\"\" type=\"text\"></label><label><h4>State:</h4><input name=\"state\" value=\"\" type=\"text\"></label><label><h4>Zip Code:</h4><input name=\"zip\" value=\"\" type=\"text\"></label></div>";
      }



      echo "After purchase, points will be removed from your account.  You will be receiving an email within the day about your order.  If the order does not go through for some reason, your points will be refunded.";

                echo "</form></div>"; 

             }




        } else {
            echo "<h2>Redeem Failed!</h2><p>You clicked a bad link.  Please click a link from the Rewards Page.</p>";   
        }

        } else {
        echo "<h2>Redeem Failed!</h2><p>You need to be logged in to place an order</p>";    
        }

    ?>

The boolen is give at line 21. Ignore all the code at the bootom and tell me line to solve the probelm.

Boolen is given at LINE-21

echo "......."
on line no 20 you forgot to put ;
it should be
echo ".......";

Thanks everyone for all your help. I found the common mistake

I wrote: SELECT * FROM rewards WHERE rewardId = $rewardId
Supposed to be SELECT * FROM rewards WHERE rewardId = '$rewardId'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.