Jump to content

[SOLVED] login script help


berry05

Recommended Posts

i have the right username and the right two passwords and when i enter it to the fields and i submitit says login failed when its suppose to say login ok... any help?

<?php

$con = mysql_connect("localhost","root","");
if(!$con) die('Could not connect: ' . mysql_error());
mysql_select_db("register", $con);

$username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE;
$password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE;
$password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE;

if($_POST['submit']){

if(!$username) die('username not set');
if(!$password1) die('Password1 not set');
else $password1 = md5($password1);
if(!$password2) die('Password2 not set');
else $password2 = md5($password2);

$query = "SELECT username, id FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'";
$result = mysql_query($query) or die( mysql_error());
if($row = mysql_fetch_assoc($result)){
	echo 'login ok';
} else {
	echo 'login failed';
}
} else {
?>
<html>
<title>Login Page</title>
<body> 

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <label>
  Username: 
  <input type="text" name="username" id="username">
  </label>
  <p>Password1: 
    <label>
    <input type="password" name="password1" id="password1">
    </label>
  </p>
  <p>Password2: 
    <label>
    <input type="password" name="password2" id="password2">
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit">
    </label>
  </p>
</form>
</body>
</html>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/136294-solved-login-script-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.