Jump to content

MySQL returns wrong number of rows from $_GET value


Johns3n

Recommended Posts

Hi PHPfreaks.com

 

I'm having some trouble with some code that should be straight forward!

 

When i run following code:

<?php
$content->query(mysql_real_escape_string($_GET['slug']));
?>

 

it does the following:

<?php
class content {
public function query($slug){
	if(empty($slug)){
		$slug = "forside";
	}
	$query = sprintf("SELECT id FROM komoono_sider WHERE slug = '".$slug."'"); 
	$result = mysql_query($query);
	echo count($result);
}
}
$content = new content;
?>

If the slug variable is empty it should be set to "forside" and when i set it to some values that i KNOW are in the database it all works perfectly and the count is correct!

However when i set the slug variable to something i KNOW that isn't in the database it returns the wrong count it still says 1 record found when it should say 0!

 

I think i starred myself blind at the problem, but i'm not sure! Hope you guys can help me with something that should have been straight forward :(

 

EDIT:

You can try it here: http://johns3n.net/none/classes/

 

?slug=forside AND ?slug=underside

are both in the database so there the count returned should be 1 if you use those, but using i.e ?slug=randomthing still returns 1 on the screen.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.