...

View Full Version : Validating system user



badidoy
03-06-2009, 02:38 AM
Hi, i have a problem regarding validating user from login form, matching to the registered user in mysql database.

here's the code:

login form codes:

<html>
<form method="POST" action="login.php">
<font color="white">Username <input type="text" name="username"><br>
<font color="white">Password <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</html>

this is the login.php page:

<?php

$my_connection = mysql_connect('localhost','root','');
if(!$my_connection)
{
die('Could not connect: '.mysql_error());
}
echo'Connected Succesfully to mySQL server' . '<br><br>';
$my_database = mysql_select_db('mydb');
if(!$my_database)
{
die("Could not find database: ".mysql_error());
}



$select_user = mysql_query('select * from users where username =
"' . $_POST['username'] . '" and password = "' .$_POST['password'] . '"')or die(mysql_error());



if (mysql_num_rows($select_user) != 0) {

session_start();
session_register('authorized');
$_SESSION['authorized'] = true;

header("Location: protected_content.php");
exit;

} else {

header("Location: login_form.php");
exit;

}


it seems nothing happened, the condition is always '0' why is that?

the value of conditional statement is always zero.

im using an encryption of md5 for the password, please help...thanks in advance

ninnypants
03-06-2009, 02:45 AM
You have some misplaced quotes here:

password = '".md5($_POST['password'] )."'")or die(mysql_error());

Also some of your parenthesis were misplaced.

badidoy
03-10-2009, 10:02 AM
Oh, thank you very much...Buddy!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum