Jump to content


Photo

checking an id


  • Please log in to reply
4 replies to this topic

#1 firelior

firelior
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 September 2006 - 07:11 AM

Hi,
I got a problem, I want to check the id that im sending via $_GET
and I want to check if it exist
this is my code:
function check_id($id){
 			$sql="select * from ".$this->table." where id= ".$id;
			if(mysql_query($sql,$this->link)){
				if($row=mysql_num_rows($sql)==1){
					return true;
				}
			return false;
			}
			return false;
	}
please help thanks

#2 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 September 2006 - 07:25 AM

what error are you getting?
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#3 firelior

firelior
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 September 2006 - 07:32 AM

I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
and also, it doesn't check if the id exists:|

#4 firelior

firelior
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 September 2006 - 07:40 AM

never mind fixed the problem..here is the fixed:
function check_id($id){
 			$sql="select * from ".$this->table." where id= ".$id;
			$result=mysql_query($sql);
			while($row=mysql_fetch_object($result)){
				if($row->id==$id){
					return true;
				}
			return false;
			}
			return false;
	}


#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 September 2006 - 08:14 AM

A bit inificient. Try...

function check_id($id) {
    $sql = "SELECT id FROM $this->table WHERE id=$id";
    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result)) {
            return true;
        }
    }
    return false;
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users