I try to check the box, but after refreshing the page, if the box is checked, the database will be updated with "yes", but the database will automatically update it to "no", even if this box is checked checked with local.store, I hope that someone can help me. This is my code.
<form action="" method="POST">
<label for="option1">Waarschuwingsbericht inschakelen voordat het volgende pack wordt geopend als jou pack boven de 200.000 waard is?</label><input id='option1' type="checkbox" name="checkbox" value="yes"><br>
<input type="submit" value="Opslaan en nog een pack openen">
</form>
<?
if(isset($_POST['checkbox'])){
$sql = "UPDATE users SET puntenchecked = 'yes' WHERE username = '" . $usernamez . "'";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
}
else {
$sql = "UPDATE users SET puntenchecked = 'no' WHERE username = '" . $usernamez . "'";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
}
?>
<script>
$(function(){
var test = localStorage.input === 'true'? true: false;
$('input').prop('checked', test || false);
});
$('input').on('change', function() {
localStorage.input = $(this).is(':checked');
console.log($(this).is(':checked'));
});
</script>
source
share