cheesybiscuits Posted April 4, 2012 Share Posted April 4, 2012 Hi people, My script is for my game, it is to see whether a player has already started a challenge (it is recorded to a table in my database). If the challenge has already been started, then the button to accept the challenge is disabled. But if the challenge hasn't been accepted yet, then the button is clickable. The problem though is the mysql_num_rows function isn't returning 0 like it should (meaning the challenge has not been started) and instead the button is being disabled. <?php session_start(); include('functions.php'); connect(); ?> <!DOCTYPE html> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <?php if (isset($_SESSION['userid'])) { include('safe.php'); ?> <ul id="tab-nav"> <li><a href="stats.php" id="tab-character">Character</a></li> <li><a href="games.php" class="active" id="tab-games">Games</a></li> <li><a href="account.php" id="tab-account">Account</a></li> </ul> <div id="wrapper"> <h2 id="name">Select a Challenge</h2> <ul id="table-view"> <li> <fieldset> <legend>"Easter Egg" Challenge</legend> <div id="rewards"> <p class="instructions"> Find each of the 4 "Easter Egg" barcodes around the university campus. </p> <p> Rewards: Every egg is worth <span class="stat">50</span> XP and <span class="stat">35</span> gold coins. </p> </div> <form action="games.php" method="POST"> <?php $check = mysql_query(" SELECT start1 FROM chal1 WHERE userid='".$_SESSION['userid']."' ") or die ("Could not select database from chal1"); if (mysql_num_rows($check)>0) { echo " <button class=\"buttons\" type=\"submit\" name=\"start1\" disabled=\"disabled\"> Accept challenge </button> "; } else { echo " <button class=\"buttons\" type=\"submit\" name=\"start1\"> Accept challenge </button> "; } ?> </form> </fieldset> </li> <li class="even"> <fieldset> <legend>Increase Strength</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the Sports Centre. </p> <p> Rewards: Every time you visit the Sports Centre you'll receive <span class="stat">2</span> Str. points. </p> </div> <form action="games.php" method="POST"> <button class="buttons" type="submit" name="start2"> Accept challenge </button> </form> </fieldset> </li> <li> <fieldset> <legend>Increase Intelligence</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the university Library. </p> <p> Rewards: Every time you visit the Library you'll receive <span class="stat">2</span> Int. points. </p> </div> <form action="games.php" method="POST"> <button class="buttons" type="submit" name="start2"> Accept challenge </button> </form> </fieldset> </li> </ul> </div> <div id="footer"> <a class="buttons" href="logout.php">log me out</a> </div> <?php } else { die (" <div id=\"wrapper\"> <p>Opps! You don't seem to be logged in...</p> <a class=\"buttons\" href=\"index.php\">login now</a><br /> <p>Don't have an account? No worries, just <a class=\"buttons\" href=\"register.php\">register for one.</a></p> </div> "); } ?> Anyone know what could be wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260308-mysql_num_rows-problem/ Share on other sites More sharing options...
chriscloyd Posted April 4, 2012 Share Posted April 4, 2012 My best guess would be that there is no challenge started in the table...? Quote Link to comment https://forums.phpfreaks.com/topic/260308-mysql_num_rows-problem/#findComment-1334221 Share on other sites More sharing options...
cheesybiscuits Posted April 4, 2012 Author Share Posted April 4, 2012 There isn't, the value is 0, so mysql_num_rows shouldn't return anything right? so the button shouldn't be disabled, it should be clickable...or have I got confused with something here? Quote Link to comment https://forums.phpfreaks.com/topic/260308-mysql_num_rows-problem/#findComment-1334283 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2012 Share Posted April 4, 2012 Your query is finding one or more rows in the table. If that's not the result you expect, you need to troubleshoot why. Have you directly examined the data in your table to see if there is or is not a row with the current userid in it? Do you know for a fact that $_SESSION['userid'] contains the value you think it does? Debugging programming problems involves checking what your code and data is actually doing to find out at what point your code and data is doing what you expect and at what point they are not. I can guarantee that the problem lies somewhere between those two points. If you don't check what's actually going on with your data values or you don't narrow down the problem to a specific statement, a specific variable, or a specific value, you cannot find what is causing the problem (we cannot because we don't have access to your server and your data.) Quote Link to comment https://forums.phpfreaks.com/topic/260308-mysql_num_rows-problem/#findComment-1334298 Share on other sites More sharing options...
cheesybiscuits Posted April 4, 2012 Author Share Posted April 4, 2012 I think it has been fixed now, checked code every step of the way, rearranged the code, didn't really change anything, but now it works. Quote Link to comment https://forums.phpfreaks.com/topic/260308-mysql_num_rows-problem/#findComment-1334342 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.