[SOLVED] Why can't I pull data out of my query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Seona
Forum Commoner
Posts: 33
Joined: Wed Dec 08, 2004 11:04 pm

[SOLVED] Why can't I pull data out of my query?

Post by Seona »

Hi guys,

I have the following code:

Code: Select all

<?php
		/* declare some relevant variables  */
		$DBhost = "localhost";
		$DBuser = "username";
		$DBpass = "password";
		$DBName = "myDB";
		$table = "category";
		/* connect to database */
		$link = mysql_connect($DBhost,$DBuser,$DBpass);
		@mysql_select_db("$DBName") or die("Unable to select database $DBName"); 
		/* create the query to compare the form data with the user table */
		$sqlquery = "SELECT * FROM $table WHERE ID = $ID";
		/* run the query and check it worked */
		$result = mysql_query($sqlquery,$link);
		if (!$result = mysql_query($sqlquery,$link))
			exit("Illegal query");
		/* get the number of rows returned by the query */
		$number = mysql_num_rows($result);
		
		print "this is " . $row["CategoryName"] . "<br>";
		print "this is " . $row["ImageLocation"];
?>
The problem I have is that those last two rows there aren't returning anything. I get the absolute text, but no database data.

What have I done wrong? Almost the exact same code has worked on other pages. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forgot to fetch the row. ;)
Seona
Forum Commoner
Posts: 33
Joined: Wed Dec 08, 2004 11:04 pm

Post by Seona »

:oops: Oh yeah... I knew that... really...

Thanks. :)
Post Reply