Yesterday I have posted some code asking how the user can update a password through a form. Look here
However after updating the password, I couldn't login though my android app. So I decided to change a bit the forgotpassword.php file.
<?php
session_start();
require "../init.php";
ini_set('display_errors', 1);
if(isset($_POST['update'])){
$email = $_POST['email'];
$user_name = $_POST['user_name'];
$password = $_POST['user_pass'];
$passwordEncrypted = sha1($user_pass);
$confpassword = $_POST['confirm_pass'];
$confPasswordEncrypted = sha1($confirmPass);
if($password !== $confpassword){
echo "<script>alert('Passwords are not equal')</script>";
}else{
$select_query = "SELECT * FROM user_info";
$run_select_query = mysqli_query($con,$select_query);
while ($row_post=mysqli_fetch_array($run_select_query)){
$_SESSION['id'] = $row_post['id'];
$user_id = $_SESSION['id'];
$useremail = $row_post['email'];
$username = $row_post['user_name'];
var_dump($user_id);
if($useremail == $email AND $username == $user_name){
//echo "<script>alert('$useremail')</script>";
//echo "<script>alert('$username')</script>";
echo "<script>alert('$id')</script>";
$update_posts = "UPDATE user_info SET user_pass='$passwordEncrypted',confirm_pass ='$confPasswordEncrypted'
WHERE $id='$_userid'";
$run_update = mysqli_query($con,$update_posts);
//var_dump($user_name);
echo "<script>alert('Password Has been Updated!')</script>";
}else{
echo "<script>alert('No email or username was found')</script>";
}
}
}
}
?>
But now the password is not updated as it was before. There is something wrong in the update statement or a line before that. The $_SESSION['id'] is not null so the select query works fine.
Any ideas?
Thanks.