First, I just wanna say thanks for the help! I've just joined this site and a lot of you guys have been very helpful and patient! (:
So, my problem is with the log in form. It allows me to log in even though the wrong information is entered. I'm new to pdo and I've just converted all my Mysql functions to pdo so I'm positive I went wrong somewhere.
Here is my log in script:
<?php
//Login script
if (isset ($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); //filter everything but numbers and letters
$password_login = preg_replace('^A-Za-z0-9)#i','', $_POST["password_login"]); //filter everything but numbers and letters
$password_login=md5($password_login);
$db = new PDO('mysql:host=localhost;dbname=socialnetwork', 'root', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id FROM users WHERE username = '$user_login' AND password = '$password_login' LIMIT 1";
$db->prepare($sql);
if ($db->execute(array(
'$user_login' => $user_login,
'$password_login' => $password_login))); {
if ($sql->rowCount() > 1){
while($row = $sql->fetch($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["user_login"] = $user_login;
$_SESSION["password_login"] = $password_login;
exit("<meta http-equiv=\"refresh\" content=\"0\">");
} else {
echo 'Either the password or username you have entered is incorrect. Please check them and try again!';
exit();
}
}
}
?>
and here is the form :
<form action="home.php" method="post">
<center><input type ="text" size="25" name="User_login" id="user_login" placeholder="username"/>
<input type ="password" size="25" name="user_password" id="user_password" placeholder="password"/><br />
<input type ="submit" name="button" id="button" value="login to your account!"/></center>
</form>
Any ideas on how to fix this?