I have a form with 10 checkboxes based on user id, but when i check a box in my database i see that only user id 1 checkbox is saving.. please see my code below, any help appreciated!
HTML:
<form method="post" action="" id="prezente" uid="<?php echo $row['id'];?>">
<input type="checkbox" name="day1" id="day1" value="1" class="form-check-input">
<input type="checkbox" name="day2" id="day2" value="1" class="form-check-input">
<input type="checkbox" name="day3" id="day3" value="1" class="form-check-input">
And so on until day10 ..
</form>
Javascript:
$(document).ready(function(){
$('#day1,#day2,#day3').click(function(){
var id = $('#prezente').attr('uid');
var day1 = $('input[name=day1]:checked').val();
var day2 = $('input[name=day2]:checked').val();
var day3 = $('input[name=day3]:checked').val();
$.ajax({
url: 'sql/add-days.php?uid='+id,
type: 'post',
data: { day1: day1,day2: day2,day3: day3 },
success:function(data){
alert("success");
}
});
});
});
add-days.php file:
// Make a MySQL Connection
$db = mysqli_connect("localhost", "stelelea_anapp", "fidodido", "stelelea_anadanceapp");
$day1 = $_POST['day1'];
$day2 = $_POST['day2'];
$day3 = $_POST['day3'];
$uid = $_GET['uid'];
$query = mysqli_query($db,"UPDATE `inscrieri` SET day1='$day1',day2='$day2',day3='$day3' WHERE id = $uid");
Aucun commentaire:
Enregistrer un commentaire