I'm trying to set up a GPT-site. When I want to test the redeem method, I get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in (blabla-link, not imporant)/redeem.php on line 39

I've tried some stuff, but nothing seems to be working. Does anybody know what the problem is? All tables and rows exist.

redeem.php code:

<?php include("function.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inwisselen • <?php echo $siteName; ?></title> 
<?php include("headscript.php"); ?>
    <?php include("logscr.php"); ?>
<div id="wrapper">
  <div id="header">
    <div class="header_top">
      <div class="top">
        <div class="logo"> <a href="#"></a> </div>
      <div class="clear"></div>
    <div class="header_bottom">
<?php include("buttons.php"); ?>
       <?php include("menu.php"); ?>
  <div id="body">
    <div class="box">
            $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>Inwisselen mislukt!</h2><p>Geen genoeg punten voor dit item.</p>";
             } else {
                  $reward = mysql_query("SELECT * FROM rewards WHERE rewardId = $rewardId");
                 echo "<h2>Bevestig koop!</h2>";
                 echo "<div style=\"padding:10px; border:1px solid #557453; background:url(../images/boxbg.png);\">";
                 while($row = mysql_fetch_array($reward))
      echo "<h3>".$row['title']."</h3> <img style=\"margin:5px;\" src=\"". $row['img']."\" width=\"150\" height=\"150\" /><br />" .$row['desc']. "<br><h4 style=\"display:inline\">Huidig aantal punten:</h4> $myPoints <img src=\"images/point.png\" /><br> <h4 style=\"display:inline\">Punten:</h4> ". $row['points']." <img src=\"images/point.png\" /><br> <h4 style=\"display:inline\">Punten over:</h4> ". ($myPoints - $row['points'])." <img src=\"images/point.png\" /><br><br>";

      echo "<form id=\"orderForm\" action=\"order.php\" method=\"post\"> 
      <input type=\"hidden\"
          <input type=\"hidden\"
          <input type=\"hidden\"
      if($row['type'] == "email"){
          echo "<input type=\"hidden\"
          $userEmail = mysql_result(mysql_query("SELECT email FROM users WHERE userId = '$userId'"), 0);
        echo "<div class=\"box contactbox\"><h3 style='display:inline;'>Versturen naar...</h3><label><h4>Emailadres:</h4><input name=\"sendto\" value=\"$userEmail\" type=\"text\"></label></div>";
      } else if($row['type'] == "ship"){
                  echo "<input type=\"hidden\"
          $userEmail = mysql_result(mysql_query("SELECT email FROM users WHERE userId = '$userId'"), 0);
        echo "<div class=\"box contactbox\"><h3 style='display:inline;'>Versturen naar...</h3><label><h4>Straat + Huisnummer:</h4><input name=\"street\" value=\"\" type=\"text\"></label><label><h4>Stad:</h4><input name=\"city\" value=\"\" type=\"text\"></label><label><h4>Provincie:</h4><input name=\"state\" value=\"\" type=\"text\"></label><label><h4>Postcode:</h4><input name=\"zip\" value=\"\" type=\"text\"></label></div>";

      echo "<a href=\"#\" onclick=\"javascript: document.forms['orderForm'].submit();\" ><img border:0px\" src=\"/images/purchase.png\" /></a><br><p>Na de aankoop worden de punten direct van je account afgehaald. Je krijgt een email binnen 24 uur met details. Als het product niet kan worden geleverd, worden je punten teruggestort.</p>";
                echo "</form></div>"; 


        } else {
            echo "<h2>Inwisselen mislukt!</h2><p>Je hebt op een ongeldige link geklikt.</p>";   

        } else {
        echo "<h2>Inwisselen mislukt!</h2><p>Je moet hiervoor ingelogd zijn.</p>";  


  <div id="footer">
    <?php include("footlinks.php"); ?>

<?php include("footer.php"); ?>

Recommended Answers

All 3 Replies

Member Avatar

$reward hasn't returned a resource. Your problem is the query. Echo out the query to see if it's what you expect. If so, copy if from the screen and run it in a phpmyadmin sql window - see what happens.

$reward = mysql_query("SELECT * FROM rewards WHERE rewardId = $rewardId");
echo "SELECT * FROM rewards WHERE rewardId = $rewardId";

I got; SELECT * FROM rewards WHERE rewardId = fano

When in phpMyAdmin, I got this: #1054 - Unknown column 'fano' in 'where clause'

Fixed it, forgot the ''s in
$reward = mysql_query("SELECT * FROM rewards WHERE rewardId = '$rewardId'");

Thanks anyway.

Be a part of the DaniWeb community

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