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

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
hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

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

Post 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]
Mohamed
Forum Newbie
Posts: 21
Joined: Fri Jan 19, 2007 6:59 pm
Location: Seattle

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

Post 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 );
Wade
Forum Commoner
Posts: 41
Joined: Mon Dec 18, 2006 10:21 am
Location: Calgary, AB, Canada

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

Post by Wade »

Where is $cadn being set? from what I can see it's nothing so the query returns nothing...
Post Reply