Jump to content


Photo

Login Script


  • Please log in to reply
4 replies to this topic

#1 ytmnd522

ytmnd522
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 June 2006 - 06:50 PM

Hello guys.. Im having a hard time loging a user in. This is my script.. When I submit the data it just refreshes with no response if the user was found on da database or anything..what's up with my script.
I have a mysql database named "mike" with a few records of users with passwords.
thanks in advanced.

<? session_start()?>

<html>
<body>
<form action="vtcsignin.php" method="post">
users:
<INPUT type="text" name="user"><br>
password:
<INPUT type="password" name="password"><br>
<INPUT type="submit">
</form>
</body>
</html>
<?

if(isset($_POST['user']) && isset($_POST['pass'])){ 
    if($logged_in_user == $user){
        echo $_POST['user'] . " Your are already logged in";
    exit;
    
    }
}

$db = mysql_connect("localhost","root") or die ("cant connect to database");
mysql_select_db("mike", $db) or die("could not select database");
$result = mysql_query("SELECT * FROM users WHERE userName = '".$user."' AND userPassword = PASSWORD('".$pass."')");

if(!$result){
    print "no information brought back";
}

if(mysql_num_rows($result) > 0){
 $_SESSION['logged_in_user']=$user;
 echo "welcome, " . $user;
 exit;
}elseif(mysql_num_rows($result)==0){
    echo "No record found in the database";
    session_destroy();
}


?>


#2 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 08:40 PM

if(mysql_num_rows($reuslt) > 0){
shouldn't that be $result?
[table]



Don't worry, the printer fairies will sort it out.

#3 ytmnd522

ytmnd522
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 June 2006 - 01:05 AM

yea i noticed that..and I thought that was the problem..but turns out it's not. BTW im running php 4.3.10

#4 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 10 June 2006 - 02:07 AM

[!--quoteo(post=381998:date=Jun 9 2006, 01:50 PM:name=MikeyLopez)--][div class=\'quotetop\']QUOTE(MikeyLopez @ Jun 9 2006, 01:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hello guys.. Im having a hard time loging a user in. This is my script.. When I submit the data it just refreshes with no response if the user was found on da database or anything..what's up with my script.
I have a mysql database named "mike" with a few records of users with passwords.
thanks in advanced.

<? session_start()?>

<html>
<body>
<form action="vtcsignin.php" method="post">
users:
<INPUT type="text" name="user"><br>
password:
<INPUT type="password" name="password"><br>
<INPUT type="submit">
</form>
</body>
</html>
<?

if(isset($_POST['user']) && isset($_POST['pass'])){ 
    if($logged_in_user == $user){
        echo $_POST['user'] . " Your are already logged in";
    exit;
    
    }
}

$db = mysql_connect("localhost","root") or die ("cant connect to database");
mysql_select_db("mike", $db) or die("could not select database");
$result = mysql_query("SELECT * FROM users WHERE userName = '".$user."' AND userPassword = PASSWORD('".$pass."')");

if(!$result){
    print "no information brought back";
}

if(mysql_num_rows($result) > 0){
 $_SESSION['logged_in_user']=$user;
 echo "welcome, " . $user;
 exit;
}elseif(mysql_num_rows($result)==0){
    echo "No record found in the database";
    session_destroy();
}
?>
[/quote]

I dont see where these two variables are set
$logged_in_user
$user

"Syntax error" .. WHERE THE **** IS IT?!

#5 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 11 June 2006 - 07:21 AM

You are relying on register globals to be ON here, and you are querying regardless of POST or not being set.
AND you are checking for posted variable "pass" while your password textfield is named "password".
Work your way with this one, i've not included a "is logged in"-check though.
<?
session_start()

if(isset($_POST['submitform']))
{
if(!empty($_POST['user']) || !empty($_POST['pass']))
{
$user = htmlspecialchars($_POST['user']);
$pass = htmlspecialchars($_POST['pass']);

$db = mysql_connect("localhost","root") or die ("cannot connect to database");
mysql_select_db("mike", $db) or die("could not select database");

$result = mysql_query("SELECT * FROM users WHERE userPassword = PASSWORD('$pass') AND userName = '$user'");

if(mysql_num_rows($result) == "1")
{
$_SESSION['logged_in_user'] = $user;
echo "welcome, " . $user;

exit();
}
else
{
echo "No record found in the database";
}
}
else
{
echo "Please fill out both username and password field..";
}
}
echo <<<_HTML

<form action = "vtcsignin.php" method = "post">
users: <INPUT type = "text" name = "user"><br>
password: <INPUT type = "password" name = "pass"><br>
<INPUT type = "submit" name = "submitform">
</form>

_HTML;

?>
You should also consider moving away from using PASSWORD in your query as it's not supported in newer mysql versions. Move to md5 or sha1 instead.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users