Page 1 of 1

I Don't understand why can't make a SELECT!

Posted: Fri Feb 16, 2007 10:33 am
by hmsg
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

     I'm making a script in php to get some values from a mysql DB but for a reason i don't understand why i can't get any select from it!!!! 

     here is my code:

Code: Select all

<?php

        $sql_select = "SELECT * FROM user_data WHERE cadn_user = '$cadn'";
	$resultado = mysql_db_query($database_BD ,$sql_select);
        
         if($resultado){
		$id_user = mysql_result($resultado,0,0);
		return  $id_user;
	}
	else{
		return 0;
	}

       ?>
The problem is that in the variable $resultado nothing happens, i've already try a simple query like "SELECT * FROM user_data" and i get nothing in $resultado, i don't understand why! This means that the script always enter in the else part and never enter in the if part!! and the table have records in it :)

The conection to DB is ok, i've already tested. Please help me understand why


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: I Don't understand why can't make a SELECT!

Posted: Fri Feb 16, 2007 12:31 pm
by Mohamed
hmsg wrote:

Code: Select all

<?php

        $sql_select = "SELECT * FROM user_data WHERE cadn_user = '$cadn'";
	$resultado = mysql_db_query($database_BD ,$sql_select);
        
         if($resultado){
		$id_user = mysql_result($resultado,0,0);
		return  $id_user;
	}
	else{
		return 0;
	}

       ?>

mysql_qeury() take two prameters which are string query and link identifier
mysql_query ( string query, [resource link_identifier] ). so in your code you inter changed the two variables and you wrote mysql_db_query($database_BD ,$sql_select); instead of mysql_db_query($sql_select, $database_BD );

Re: I Don't understand why can't make a SELECT!

Posted: Fri Feb 16, 2007 2:27 pm
by Wade
Where is $cadn being set? from what I can see it's nothing so the query returns nothing...