Login issues

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
ibelimb
Forum Newbie
Posts: 18
Joined: Wed Jun 19, 2002 2:59 pm
Location: New York, USA

Login issues

Post by ibelimb »

Hey,
Im taking my login script that uses sessions and converting it to MySQL instead of 2 variables within the script.

i get a parse error from login.inc.php
on line 23 which is

Code: Select all

?>
I think whats causing it is im not closing a bracket, but i cant seem to find it. Can you find the cause? heres the code:

Code: Select all

function user_isloggedin($name,$pass) { 
   if(isset( $name ) && isset( $pass ) && ($auth = "false")) {
 mysql_connect($mysql_server, $mysql_user, $mysql_pass);
 mysql_select_db($mysql_db);
 $sql = "SELECT * FROM users WHERE user="$name" AND pass="$pass");
 $result = mysql_query($sql);
 $num = mysql_numrows($result);
 if ($num != 0) {
 return 1;
}
} else { 
      return 0; 
   } 
}
Thanks,
Limb
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

1) $auth = "false" causes $auth to be set to "false" even in a if clause
2) $sql = "....."); a bracket too much

Code: Select all

function user_isloggedin($name,$pass)
{ 
	if(isset($name) && isset($pass) && $auth != "false") 
// not quite sure about the !=, but it's the only operator that would make sense to me
// edit: it doesn't make sense even this way, but what do I know ;)
	{ 
		mysql_connect($mysql_server, $mysql_user, $mysql_pass); 
		mysql_select_db($mysql_db); 
		$sql = "SELECT * FROM users WHERE user="$name" AND pass="$pass"; 
		$result = mysql_query($sql); 
		$num = mysql_numrows($result); 
		if ($num != 0)
			return 1;
//you're aware of returning void if $num==0 ?
	}
	else
		return 0; 
}
to find errors like the second one try highlighting editors like PHPEdit (which shows correlating brackets as well)
Post Reply