EDIT: Clicked post way too early on this!! Basically the values don't pull through and update the database at all but it treats it as though it is a success with no error messages.
I wonder if anyone can solve this for me.
I've got a HTML form that auto submits when a checkbox is ticked and/or unticked.
The HTML looks like this:
<form action='propupdate.php' id='propupdate' method='post'>
<input type="hidden" value="<?php echo $userData['id'] ?>" id="ID" form="propupdate">
<input type="checkbox" value="Yes" id="slideThree" name="check" onchange="document.getElementById('propupdate').submit()" <?php echo ($userData['prop']=='Yes' ? 'checked' : '');?> form="propupdate"/>
<label for="slideThree"></label>
</form>
When I check the hidden value it is correct, I've also tested the php which makes it auto checked or unchecked and this works. At first I though the autosubmit was missing the hidden input so I tried adding in form= into the inputs but this didn't seem to work.
propupdate.php looks like this:
<?php
include 'index.php';
include 'credentials.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Create variables
$ID=$_POST['ID'];
$prop=$_POST['slideThree'];
$sql = "UPDATE users SET prop='$prop' WHERE ID='$ID'";
if ($conn->query($sql) === TRUE) {
header("Location:example.com");
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
Any help is massively appreciated!