PHP redirect failing

时间:2017-08-13 13:44:57

标签: php

I know this is a commonly asked question, however I've checked for white space, checked the encoding of the files and I can't work this out.

When I submit this form it should redirect back to 'successful_login.php' however it doesn't it just stays on the same page.

available_update.php

<?php
  include 'credentials.php';
  $conn = new mysqli($servername, $username, $password, $dbname);
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }
  $ID=$_POST['ID'];
  $available=$_POST['available'];
  $sql = "UPDATE users SET available='$available' WHERE ID='$ID'";
  if ($conn->query($sql) === TRUE) {
    header("http://www.jtsanderson.co.uk/users/successful_login.php");
  } else {
    echo "Error updating record: " . $conn->error;
  }
  $conn->close();
?>

credentials.php

<?php
  $servername = "****";
  $username = "****";
  $password = "****";
  $dbname = "****";
?>

HTML Form

<div class="w3-half">
  <form action="availableupdate.php" method="post" id="available">
    <input type="hidden" name="ID" value="<?php echo $userData['id'] ?>">
    <input type="hidden" name="available" value="Yes">
  </form>
  <button type="submit" form="available" name="signupSubmit" 
          class="w3-button w3-block w3-green w3-section" title="Accept"><i class="fa fa-check"></i></button>
</div>

1 个答案:

答案 0 :(得分:0)

You are using header() incorrectly.

You need to change

header("http://www.jtsanderson.co.uk/users/successful_login.php");

to

header("Location: http://www.jtsanderson.co.uk/users/successful_login.php");