Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function problem

Status
Not open for further replies.

Dweezel

Technical User
Joined
Feb 12, 2004
Messages
428
Location
GB
Could anybody tell me why the following piece of code will work fine when written to the page that contains my connect statement, but when I put it in an included function file it won't work?

Code:
$query="select * from users
        where username = '$username'
		and passwd = password('$password')";
		
		$result=mysql_query($query);
		
		if(!$result)
		{              
		echo 'Could not make query';
		exit;
		}
		
		if(mysql_num_rows($result)>0)
		{
		echo 'welcome back';
		exit;
		}
		
		else
		echo 'username and password are not correct';


I expect I'm doing something basic wrong. Cheers.





 
When in the same page as the mysql_pconnect it does as it should:
when a correct username and pass are entered it echoes 'welcome back'

when incorrect are entered it echoes 'username and password are incorrect'


When its called from the required file as a function all I get is the 'username and password are incorrect' whether or not they actualy are incorrect.

cheers
 
Sorry Slepinir I'll try and be clearer.

The code above is working as as it should, with no problems.

If I take the entire block of code above, select it, and then cut it from the page and paste it into a file that contains my functions (the functions file is already included in the php page which I'm cutting the code from), and define it as a function (db_query() for example) and then try calling that funcion from the page that I cut the code from. Then I get the problems stated in my last post.


 
Thanks Slepinir.
I'm using javascript and php at the same time and I keep getting the rules of the two confused.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top