Jump to content

mysql_num_rows problem


cheesybiscuits

Recommended Posts

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

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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.