select query

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
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

select query

Post by cmdo »

Hi all,
I'm trying to fetch some data from my mysql DB.
Example:
The user uses email to login and then it says hello name

I have the following code:

Code: Select all

$busca = mysql_query("SELECT nome FROM users WHERE email='$name'");
		while ($info = mysql_fetch_array($busca))
		{
		    print "teste".$info['nome'];
		}
How can I do this?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: select query

Post by Celauran »

At a glance it looks OK. What isn't working?
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

Re: select query

Post by cmdo »

I get this error:


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/boleias/home.php on line 9
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: select query

Post by Celauran »

So mysql_query is returning FALSE, which means there's a problem with the query itself. Have you tried running the query manually?

Code: Select all

$busca = mysql_query("SELECT nome FROM users WHERE email='$name'") or die(mysql_error());
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

Re: select query

Post by cmdo »

Yeah, if I do the query in mysql works like a charm
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

Re: select query

Post by cmdo »

Worked, I just made this changes:

Code: Select all

	
		@mysql_connect("localhost", "root", "root") or die("Conexão falhou");
		mysql_select_db('boleias');
		$mail = $_SESSION['username'];
		$busca = mysql_query("SELECT nome FROM users WHERE email='$mail'") or die(mysql_error());
		while ($info = mysql_fetch_array($busca))
		{
		    $nome = $info['nome'];
		}
Post Reply