-1

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>
gawi
  • 2,843
  • 4
  • 29
  • 44
James V
  • 60
  • 1
  • 7
  • This code is open to a serious sql injection. Don't go live with this, if that is your intention. – Funk Forty Niner Aug 13 '17 at 13:52
  • I did think this, but as the only inputs are hidden and there is no options in the form other than a button is it possible for anyone to change the input? – James V Aug 13 '17 at 13:53
  • Also this is only a page you can access when logged in and for a local community type project so it wouldn't be the end of the world! – James V Aug 13 '17 at 13:53

1 Answers1

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");
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
  • OMG!! Cannot believe I missed that, was coding until 4.30am and my brain is not working properly. Thank you so much for your help. – James V Aug 13 '17 at 13:46
  • You’re welcome, If it helped you, please [upvote and accept the answer](https://stackoverflow.com/help/someone-answers) Happy Coding! :) – Milan Chheda Aug 13 '17 at 13:47