I'm trying to allow logged in users of my site to be able to change their password which will then be updated in my database. When I click the submit button, I get 'Unknown column '[username]' in 'where clause'. I've tried multiple things and I can't seem to get it to work. I'm a beginner with PHP so don't have an expansive skillset, so I'm not sure what the problem could be. If anyone could help me out I'd appreciate it, thanks.
<?php
session_start();
require_once ("db_connect.php");
require_once($_SERVER['DOCUMENT_ROOT'] . '/functions/functions.php');
$oldpw = ($_POST['oldpw']);
$newpw = ($_POST['newpw']);
$conpw = ($_POST['conpw']);
$currentpw = $_SESSION['password'];
if ($_POST['change'] == 'Change') {
if ($oldpw && $newpw && $conpw) {
if ($newpw == $conpw) {
if ($db_server){
mysqli_select_db($db_server, $db_database);
$oldpw = salt($currentpw);
// check whether username exists
$query = "SELECT password FROM users WHERE 'username'= '" . $_SESSION['username'] . "'";
$result = mysqli_query($db_server, $query);
if(!$result){
$message = "<p class='message'>Error: Coud not connect to the database.</p>" ;
}else{
$newpw = salt($newpw);
$query = "UPDATE users SET password = '$newpw' WHERE username = " . $_SESSION['username'] . "";
mysqli_query($db_server, $query) or
die("Insert failed. " . mysqli_error($db_server));
$message = "<p class='message'>Your password has been changed!</p>";
// Process further here
mysqli_free_result($result);
}
}else{
$message = " <p class='message'>Your current password is incorrect.</p>";
}
}else{
$message = "<p class='message'>Your new passwords do not match.</p>";
}
}else{
$message = "<p class='message'>Please fill in all fields.</p>";
}
}
?>
This is the html I've used:
<form action='change-password.php' method='post' id="register-form">
<?php echo $message; ?>
<input class="password-field" type='password' name='oldpw' value='<?php echo $username; ?>' placeholder="Current Password"><br />
<input class="password-field" type='password' name='newpw' placeholder="New Password"><br />
<input class="password-field" type='password' name='conpw' placeholder="Confrim Password">
<input class="button" type='submit' name='change' value='Change' />
</form>