Jump to content

Issue with undefined variable


Dexlin

Recommended Posts

Hi all,

 

 

I have a class that i have written to get the lastest 3 records from the db and i have got a message saying "Undefined variable $category" in $query. I can not see what i'm doing wrong and its driving me nuts.

 

The class with the problem is as follows:

 

class Get extends DatabaseConnect {

public function __Contruct($category) {
	$this->category = $category;

}

public function Latest() {
				if (!@$this->Connect('localhost','root','')) {
					echo 'Connection Failed';
				}
				else
				{
				mysql_select_db ("film");
				$query = mysql_query("SELECT * FROM films WHERE category='$category' Limit 3");
				$rows = mysql_fetch_array($query);
				if($query)
				{
					while($rows) {

						$title = $rows['title'];
						$description = $rows['description'];
						$body = $rows['body'];
						$posted = $rows['posted'];	

					}
				}
				else
				{
					die("Problem");
				}

				}
}

}

 

Can anyone see what i have done wrong as i can't.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/266005-issue-with-undefined-variable/
Share on other sites

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.