I'll explain the code below : I'm submitting a written password inside the form where it is taken, and it updates the current password that already exists for the user (where the e-mail is the e-mail that is already there from his session, if that makes sense).
So basically if the the SQL query works (if($result)
), it should redirect us to a certain page, else it redirects us to the homepage. So it always redirects us to the homepage, thus I believe the query is wrong, but I can't figure it out. Any ideas?
<?
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// password sent from form
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "UPDATE Users SET password='$mypassword' WHERE email = {$_SESSION['email']}";
$result = mysqli_query($conn,$sql);
// If result matched $myemail and $mypassword, table row must be 1 row
if($result) {
$_SESSION['password']=$mypassword;
header("location: logged_in.php");
} else {
header("location: index.php");
}
}
?>
<?php include('head.php'); ?>
<?php include('nav.php'); ?>
<form class="form-signin" role="form" method="post" action="changepass.php">
<h2 class="form-signin-heading">Change password</h2>
<p>Please change your password.</p>
<input type="password" class="form-control" name="password" placeholder="Password" required=""/>
<button class="btn btn-lg btn-primary btn-block" type="submit">Changer le mot de passe</button>
</form>
<?php include('footer.php'); ?>