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!
Everah | Code tags are a requirement, not an option. Please use them when posting code in the forums. Also, please do not use all caps when posting. It looks like you are mad at us.
HI AGAIN EVERYBODY,
I HAVE THIS CODE TO AUTHENTICATE SOME USERS AND I'M HAVING PROBLEMS BECAUSE IS TELLING ME THAT THE PASSWORD IS WRONG AND I ALREADY CHECK WITH THE DATABASE AND IS CORRECT. I ALSO WOULD LIKE TO BE REDIRECTED TO ANOTHER PAGE AS SOON AS THE USER IS AUTHENTICATED. CAN SOMEONE PLEASE HELP ME WITH THIS ONE TOO?
<?PHP
// Configura los datos de tu cuenta
$dbhost='host';
$dbusername='username';
$dbuserpass='password';
$dbname='database';
session_start();
// Conect to database
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
if ($_POST['username']) {
//Check if username and password was sent
$username=$_POST['username'];
$password=$_POST['password'];
if ($password==NULL) {
echo "Password was not sent";
}else{
$query = mysql_query("SELECT user_email,user_pwd FROM users WHERE user_email = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
echo "Login incorrect";
}else{
$query = mysql_query("SELECT user_email,user_pwd FROM users WHERE user_email = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["s_username"] = $row['username'];
echo "You have been log correctly ".$_SESSION['s_username']." and now you can access index.php.";
}
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input name="password" type="password" id="password" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
Last edited by RobertGonzalez on Mon Aug 04, 2008 1:30 pm, edited 1 time in total.
Reason:For the love of God can you please use [php] tags around your code?
Will throw errors if that array index is not set. You might not be seeing the errors because of your error display / handling settings, but they are there. You should always check isset() or empty() rather than working on an array member that may or may not be there.
Wrap the code you post inside of either [ code ] (without the spaces) tags (you can use the button above the posting text box) or you can use [ code=php ] or even [ php ] (again, without spaces).