在PHP中更新表后重定向

时间:2016-10-12 20:55:03

标签: php mysql sql database phpmyadmin

我将解释下面的代码:我在表单中提交了一个书面密码,它会更新用户已经存在的当前密码(电子邮件是那封电子邮件)如果有意义的话,他的会话就已经存在了。)

所以基本上如果SQL查询有效(if($result)),它应该将我们重定向到某个页面,否则它会将我们重定向到主页。因此它总是将我们重定向到主页,因此我认为查询是错误的,但我无法弄明白。有什么想法吗?

<?
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'); ?>

0 个答案:

没有答案