I'm making a forum in PHP and MySQL (not a real one, just for practicing). and i made a login page. The problem is that for some reason after I'm writing the username and password and sending it, it keeps getting to the point which it gives me the echo of "wrong password or username". Yet every detail is correct (the names of the columns and the tables in my database are exactly the same in this code and the username and password are correct) so I'm guessing it's not the problem. Any help would be appreciated.
<?php
if(!empty($_POST['username'] ) && !empty($_POST['password'])){
require_once 'dbConnect.php';
$user = mysql_query("SELECT `nickname` , `id` FROM `users` WHERE `nickname` =". $_POST['username'] . "AND `password` = " .sha1($_POST['password']));
if($user){
$data = array();
$data = mysql_fetch_assoc($user);
session_start();
$_SESSION['username'] = $data['nickname'];
echo $_SESSION['username'];
}
else {
echo "wrong password or username";
}
}
else {
echo "enter a username and a password";
}
?>
<form action="index.php?page=login" method="post">
<label>username:
<input type="text" name="username" required/>
</label>
<label>password:
<input type="password" name="password" required/>
</label>
<input type="submit" value="login!" />
</form>