PHP and MySQL Form Authentication: Can't Login
Posted by: dardarj (222.127.228.---)
Date: February 03, 2008 08:41AM

I don't know what I did wrong. The queries were successful, it's just that my codes can't verify valid login usernames and passwords. I already added items in my users database and users table. I checked via SQL console the items are there. But how come it never returns a valid num?


Here are my codes.


login.php

<form name="login form" method="POST" action="validate.php">
<p> Username: <input type="text" name="username" size=15 id="username">
<p> Password: <input type="password" name="password" size=15 id="password">
<p> <input type="submit" value="Send">
</p>
</form>

validate.php

<?php

$servername = "localhost";
$dbuname = "root";
$con = mysql_connect($servername,$dbuname,""winking smiley;
$selectdb = mysql_select_db("users"winking smiley;

$username = $_POST['username'];
$password = $_POST['password'];


if (!$con){
die('Could not connect: ' . mysql_error());
}

if(!$selectdb){
die('Could not connect db: ' . mysql_error());
}

$validate = "SELECT * FROM users WHERE uname='$username' AND pword='$pword'";

$result = mysql_query($validate)
or die("Couldn’t execute query."winking smiley;

$num = mysql_num_rows($result);

if($count==1){
header("location:loginsuccess.php"winking smiley;
}
else {
header("location:loginfailed.php"winking smiley;
}
?>

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: dardarj (222.127.228.---)
Date: February 03, 2008 08:45AM

Correction:

if($num==1){
header("location:loginsuccess.php"winking smiley;
}
else {
header("location:loginfailed.php"winking smiley;
}


not $count==1

thanks. smiling smiley

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: yfastud (Moderator)
Date: February 03, 2008 02:02PM

Quote

$password = $_POST['password'];
Quote

AND pword='$pword'";
2 variables don't match; therefore, it never validate

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: dardarj (222.127.228.---)
Date: February 03, 2008 02:06PM

oh gee. how stupid of me. i'm a super newbie. waa.

thank you.

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: yfastud (Moderator)
Date: February 03, 2008 02:12PM

You're welcome anytime ;-)

BTW, it's not a good habit to use "root" user, you should check Setup Password guide and Setup Database guide on my personal websites

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: dardarj (222.127.228.---)
Date: February 03, 2008 02:16PM

oh thank you. Im'a check your guides in a bit. thank you so much.

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: atac (---.ip.tiscali.nl)
Date: February 05, 2008 12:26PM

dear Yfastud,

you appear to be the "root user" issue man to goto. I am trying to log into mysql with another user beside the "root user" but can't. Can you help me with the issue or redirect me to somewhere to find the solution and can you also give me the address(url) to your personal website it may be handy for information later, please.

sincerely,
atac.

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: yfastud (Moderator)
Date: February 05, 2008 02:53PM

You can access my personal webistes through banner on my signature, and you should check Setup Password guide and Setup Database guide on my personal websites

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: PHP and MySQL Form Authentication: Can't Login
Posted by: akadir64 (---.jogja.citra.net.id)
Date: February 20, 2008 04:25AM

I tried to code like this

$username = $_POST['username'];

But it didn't work. But when I changed into

$username = $_POST[username];

the result in $username was true. Can anyone explain it?

Regards,
Abdul

Options: ReplyQuote


Sorry, only registered users may post in this forum.