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.

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.