Page 1 of 1

select query

Posted: Tue Dec 06, 2011 9:47 am
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?

Re: select query

Posted: Tue Dec 06, 2011 9:59 am
by Celauran
At a glance it looks OK. What isn't working?

Re: select query

Posted: Tue Dec 06, 2011 10:18 am
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

Re: select query

Posted: Tue Dec 06, 2011 10:26 am
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());

Re: select query

Posted: Tue Dec 06, 2011 12:29 pm
by cmdo
Yeah, if I do the query in mysql works like a charm

Re: select query

Posted: Tue Dec 06, 2011 12:42 pm
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'];
		}