I am still working with "PHP and SQL for Dummies 4th edition". The problem I am having now is that if I should try to login with the correct password I am being told that the password is not correct, this happens for all the records I added through the PHP web file. The records I added through phpmyadmin works fine (after the removal of the encryption statements) and I can gain access to the login page after providing the correct password. I suspect the problem will be from the encryption because the password column in phpmyadmin contains the SAME ciphertext ("d41d8cd98f00b204e98009") for everything (except the record entered through phpmyadmin, which was without any encryption). I will include the part of my code that contains the encryption, maybe anyone can spot any errors in them. Code that encrypts the inputted password before checking for a match in Database:
if($num > 0) //login name was found
{
$sql = "SELECT loginName FROM Member
WHERE loginName='$_POST[fusername]'
AND password=md5('$_POST[fpassword]')";
$result2 = mysqli_query($cxn,$sql)
or die("Query died: fpassword");
$num2 = mysqli_num_rows($result2);
if($num2 > 0) //password matches
{
$_SESSION['auth']="yes";
$_SESSION['logname'] = $_POST['fusername'];
$sql = "INSERT INTO Login (loginName,loginTime)
VALUES ('$_SESSION[logname]',NOW())";
$result = mysqli_query($cxn,$sql)
or die("Query died: insert");
header("Location: New_memberpage.php");
}
Code that encrypts a newly registered user's password before it is sent to the database:
else // Add new member to database
{
$sql = "INSERT INTO Member (loginName,createDate,
password,firstName,lastName,street,city,
state,zip,phone,fax,email) VALUES
('$loginName',NOW(),md5('$password'),
'$firstName','$lastName','$street','$city',
'$state','$zip','$phone','$fax','$email')";
mysqli_query($cxn,$sql);
$_SESSION['auth']="yes";
$_SESSION['logname'] = $loginName;
The summary of my challenge is that the username/password login method only works well, when I add through phpmyadmin. I want to make it work when I register through the website, and why are all the ciphertext the same thing in the password column of my database even though I entered different password for all of them?