Jump to content

Recommended Posts

My error below returns (echos) that there is no data under the table sites to display. But, there is. Why is it doing this?

 

class_l.php

<?php

class displaySites 
{
function grabSites()
{
	$query = mysql_query("SELECT title,description,votes,dates,comments,out,in FROM sites ORDER BY id DESC LIMIT 100");

	if(mysql_num_rows($query) > 0)
	{
		while($fetch = mysql_fetch_assoc($query))
		{
			echo "
			<div id='post-1' class='post'>
			<h2 class='title'><a href='#'>". $fetch['title'] ."</a></h2>
			<h3 class='date'>Submitted on ". $fetch['date'] ."</h3>
			<div class='entry'>
			<p>". nl2br(stripslashes($fetch['description'])) ."</p>
			</div>
			<p class='meta'><a href='#'>View</a></p>
			<div class='hr'>

			</div>
			</div>
			";
		}
	}
	else
	{
			echo "
			<div id='post-1' class='post'>
			<h2 class='title'><a href='#'>Oh NOEZ!</a></h2>
			<h3 class='date'>". date("M-d-Y") ."</h3>
			<div class='entry'>
			<p>There are currently no sites to display!</p>
			</div>
			<p class='meta'>View</p>
			<div class='hr'>
				<hr />
			</div>
			</div>
			";
	}
}
}

class register
{
function createAccount()
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = md5(sha1(sha1($_POST['password'])));
	$name = mysql_real_escape_string($_POST['title']);
	$description = mysql_real_escape_string($_POST['description']);

	if(isset($username) && isset($password) && isset($name) && isset($description))
	{
		if(!$username || !$password || !$name || !$description)
		{

			echo '<table border="0"><form action="register.php" method="POST">
			<tr><td>Username</td><td><input type="text" name="username" maxlength="20"></td></tr>
			<tr><td>Password</td><td><input type="text" name="password" maxlength="30"></td></tr>
			<tr><td>Site Name</td><td><input type="text" name="title" maxlength="25"></td></tr>
			<tr><td>Site Description</td><td><textarea cols="40" rows="18" name="description" maxlength="750"></textarea></td></tr>
			<tr><td>Finish!</td><td><input type="submit"></td></tr>
			</form></table>';

		}
		else
		{
			$query = mysql_query("SELECT * FROM sites WHERE username = '$username' LIMIT 1");

			if(mysql_num_rows($query) > 0)
			{
				echo "Sorry, an account with this username already exists.";
			}
			else
			{
				$date = date("M-d-Y");
				$ip = $_SERVER['REMOTE_ADDR'];

				//create their account
				mysql_query("INSERT INTO sites VALUES (null, '$username', '$password', '$name', '$description', 0, 0, 0, '$date', '$ip', 0)");

				echo "You have successfully registered your site on NovaTops! <a href='login.php'>Login</a>";
			}
		}
	}
	else
	{
		echo "One or more of the variables are not set.";
	}
}
}

class login 
{
function verifyLogin()
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = md5(sha1(sha1($_POST['password'])));

	if(isset($username) && isset($password))
	{
		if(!$username || !$password)
		{
			echo "<table><form action='login.php' method='POST'>
			<tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr>
			<tr><td>Password</td><td><input type='password' name='password' maxlength='30'></td></tr>
			<tr><td>Finished?</td><td><input type='submit'></td></tr>
			</form></table>";
		}
		else
		{
			$query = mysql_query("SELECT * FROM sites WHERE username = '$username' AND password = '$password'LIMIT 1");

			if(mysql_num_rows($query) > 0)
			{
				echo "Congratulations! You have successfully logged in! <a href='index.php'>Home</a>";
				$_SESSION['user'] = $username;
			}
			else
			{
				echo "It seems you've typed in the wrong username and/or password. <a href='login.php'>Try Again</a>";
			}
		}
	}
	else
	{
		echo "One or more of the variables aren't set.";
	}
}
}
?>

 

index.php

 

<?php
include_once('includes/config.php');
include_once('class_l.php');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $title; ?></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
   <div class="top_text"><h1><a href="#"><?php echo $site_name; ?></a></h1>
    <h2><a href="#"><?php echo $slogan; ?></a></h2></div>
<div id="content">
	<div id="blog">
		<div id="post-1" class="post">
			<h2 class="title"><a href="#">Welcome to NovaTops!</a></h2>
			<h3 class="date">Created on April 06, 2011</h3>
			<div class="entry">
			<p>Hello there! If your viewing this message right now, your on the awesome site called NovaTops! NovaTops allows you to register
			your site in our database, and then the site's script automatically starts to rank your site. The higher your rank, the more likely
			your site's going to get a ton of views!</p>
			</div>
			<div class="hr">
				<hr />
			</div>
		</div>
		<!-- end #post-1 -->
		<?php

		$displaySites = new displaySites();
		$displaySites->grabSites();

		?>
	</div>
	<!-- end #blog -->
	<?php include_once('includes/navigation.php'); ?>
	<!-- end #sidebar -->
	<div style="clear: both; height: 1px;"></div>
</div>
<!-- end #content -->
<div id="footer">
	<p>Copyright © 2011. Design by <a href="http://www.flashtemplatesdesign.com/" title="Free Flash Templates">Free Flash Templates</a></p>
	<p><a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | <a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="This page validates as CSS"><abbr title="Cascading Style Sheets">CSS</abbr></a></p>
</div>
</div>
<!-- end #wrapper -->
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/232909-says-no-data-exists-when-it-does/
Share on other sites

"in" & "out" are reserved MySQL words.  You should always try to avoid naming columns after these words.  You either need to rename your column names and change your queries

OR

put backtics around the tables names wherever you use these reserved words.

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

"in" & "out" are reserved MySQL words.  You should always try to avoid naming columns after these words.  You either need to rename your column names and change your queries

OR

put backtics around the tables names wherever you use these reserved words.

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

 

I can't remember how many times this has happened to me, yet I still forget..... -.-

 

Thanks!

 

EDIT: Still doesn't display. <.<

 

How the hell do I manage to make so many bugs... D;

Is it because you have the functions written in your file, but you don't execute them?  Like all your variables and things are set in the file that you include_once, but you don't actually call upon the function, so the variables are blank. 

Is it because you have the functions written in your file, but you don't execute them?  Like all your variables and things are set in the file that you include_once, but you don't actually call upon the function, so the variables are blank.

 

I don't think thats the reason. If that were the reason, the text wouldn't be displayed on index.php

Your need to test, using some error checking logic in your code, if your queries executed without error before you can use mysql_num_rows(). If your query failed due to an error of some kind (returned a FALSE value instead of a result resource) you need to handle the error and report/log information about the error so that you can find and fix it. You need to -

 

1) Generate and output a 'user' message, such as 'Sorry, an error occurred and the requested operation cannot be completed!'

 

2) Generate a system error message containing the query that failed and the reason why it failed (other information such as line number and file name) and then use trigger_error to log and/or display the error information, depending on your display_errors and log_errors settings.

 

The use of reserved words that Maq pointed out would have resulted in sql syntax errors and having some error checking and error reporting/logging logic in your code for the mysql_query() statement would have show you.

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.