I have this problem with my web system. As administrator, my purpose is to register some users giving them username
,password
,firstname
and lastname
. I do that properly since all the records are inserted correctly. But when I'm trying to have access as one of those users, I cannot enter, geting the message "Username and password do not match". This is my login check code:
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username'] = $_POST['username'];
if ((!$username) || (!$password)) {
do_html_header('');
echo '<h3 style="color:#800000;">Please fill in both fields</h3><br><br></br></br>';
display_login_form();
}
else {
$sql = mysql_query('SELECT * FROM members WHERE username="'.$_POST['username'].'" AND password=sha1("'.$_POST['password'].'")') or die(mysql_error());
$login_check_member = mysql_num_rows($sql);
if($login_check_member > 0) {
while($row = mysql_fetch_array($sql)) {
$role = $row["role"];
$_SESSION['role'] = $role;
}
}
else { // Run this code if login_check is equal to 0 meaning they do not exist
do_html_header('');
echo '<h3 style="color:#800000;">The Username And Password do not match.</h3><br><br></br></br>';
display_login_form();
}
Apparently, there is a problem with my while loop. But it does work properly for those users inserted in my database via MySql console of wampserver. The problem exists only for the users inserted via the web site. The part of code that I use to insert new users (servers) is :
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$role = $_POST['role'];
$conn = mysql_connect("localhost", "root", "");
$db=mysql_select_db("buzzcafe" ,$conn);
//$username= $_SESSION['username'];
if (isset($_POST['username'])) {
if (isset($_POST['password'])) {
if (isset($_POST['firstname'])) {
if (isset($_POST['lastname'])) {
if(isset($_POST['role'])) {
$insertServer = mysql_query("INSERT INTO servers (username,password,firstname,lastname,role) VALUES('".$username."',sha1('".$password."'),'".$firstname."','".$lastname."','".$role."')")or die(mysql_error());
echo "<h5 style=color:#800000><i>The server ".$username." is now registered </i></h5>";
display_manager_menu();
}
}
}
}
}
Any ideas please?