mysql_fetch_array won't give value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cgood
Forum Newbie
Posts: 8
Joined: Mon Aug 23, 2010 10:41 pm

mysql_fetch_array won't give value

Post 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;
	}				
	
}
Last edited by cgood on Sun Aug 29, 2010 11:51 am, edited 1 time in total.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: mysql_fetch_array won't give value

Post by Gargoyle »

change

Code: Select all

if (!mysql_fetch_array($result))
to

Code: Select all

if(!$result)
cgood
Forum Newbie
Posts: 8
Joined: Mon Aug 23, 2010 10:41 pm

Re: mysql_fetch_array won't give value

Post by cgood »

Thanks. You da man. Worked perfectly.
Post Reply