Page 1 of 1

mysql_fetch_array won't give value

Posted: Sun Aug 29, 2010 12:31 am
by cgood
I'm kind of new to PHP, and I can't get this to work. I've gotten it to work for returning the entire array for a different project, but on this one, I can't figure it out. Been looking everywhere trying to figure out why it won't. For a first run, it works fine on the inset, but after that-- no luck when it goes to return the name. When I do a var_dump($row), I get bool(false) instead of what I'm looking for. Thanks in advance. Here's the code:

Code: Select all

function get_name($url, $name)
{
	db_connect();
	
	$query = sprintf(	"SELECT 
							list.id, 
							list.url, 
							list.name 
						FROM 
							list 
						WHERE 
							list.url = '%s' ",
						mysql_real_escape_string($url)
						);
	
	$result = mysql_query($query);
	
	if (!mysql_fetch_array($result))
	{
		$new_query = "INSERT INTO list (url, name) VALUES 
						('$url', $name)
						";
		mysql_query($new_query);
		return 0;
	}
	else
	{
		$row = mysql_fetch_array($result);
		$var = $row['url'];
		return $var;
	}				
	
}

Re: mysql_fetch_array won't give value

Posted: Sun Aug 29, 2010 3:27 am
by Gargoyle
change

Code: Select all

if (!mysql_fetch_array($result))
to

Code: Select all

if(!$result)

Re: mysql_fetch_array won't give value

Posted: Sun Aug 29, 2010 11:53 am
by cgood
Thanks. You da man. Worked perfectly.