I'm trying to make a password change form in php and mysql but I have problem. When I fill out the form and hit submit I got the empty error message. I'm really new in php and mysql and I don't find the problem. Here is the code detail from the public html/php:
<form action="passchange.php" method="POST">
<div class="form-group">
<label for="OldPass">Current password:</label>
<input type="password" class="form-control" id="OldPass">
</div>
<div class="form-group">
<label for="NewPass">New password:</label>
<input type="password" class="form-control" id="NewPass">
</div>
<div class="form-group">
<label for="NewPassAgain">Confirm new password:</label>
<input type="password" class="form-control" id="NewPassAgain">
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" value="">
I want to change my password
<span class="form-check-sign">
<span class="check"></span>
</span>
</label>
</div>
<button type="submit" class="btn btn-danger">Change password</button>
<div id="warn">
<?php
if(@$_GET['EmptyChangePass']==true)
{
?>
<div id="warn"><?php echo $_GET['EmptyChangePass'] ?></div>
<?php
}
?>
<?php
if(@$_GET['InvalidChangePass']==true)
{
?>
<div id="warn"><?php echo $_GET['InvalidChangePass'] ?></div>
<?php
}
?>
<?php
if(@$_GET['ValidChangePass']==true)
{
?>
<div id="warn"><?php echo $_GET['ValidChangePass'] ?></div>
<?php
}
?>
</div>
</form>
And here is the passchange.php:
<?php
$OldPass = $_POST['OldPass'];
$NewPass = $_POST['NewPass'];
$NewPassAgain = $_POST['NewPassAgain'];
if(empty($_POST['OldPass']) || empty($_POST['NewPass']) || empty($_POST['NewPassAgain'])) {
header("location:settings.php?EmptyChangePass=All fields are required");
}
else {
if ($OldPass && $NewPass && $NewPassAgain) {
require_once('connection.php');
$queryget = mysql_query("SELECT pass FROM users WHERE user='$user'");
$row = mysqli_fetch_assoc($queryget);
$OldPassDB = $row['pass'];
if ($OldPass==$OldPassDB) {
if ($NewPass==$NewPassAgain) {
$update = "UPDATE users SET pass='$NewPass' WHERE user='$user'";
$querychange = mysql_query($update);
header("location:settings.php?ValidChangePass=Password changed");
}
else {
header("location:settings.php?InvalidChangePass=Passwords are do not match");
}
}
else {
header("location:settings.php?InvalidChangePass=Passwords are do not match");
}
}
}
?>
I tried to write some text with 'echo' after 'header' but It didn't write anything. Maybe my code is wrong? I have a registration form with the same 'if' starting and that is working. Sorry for my bad english.