Does anyone knows how to code in php for every time i tick the check-box in my form? And when i tick the check-box,the value is suppose to actually inserted into an id column in my database and it will auto increase every time i tick and submit the form.
You need to use ajax. Following is the code snippet.
$('input:radio[name="tickExam"]').click(function() {
if(this.checked){
$.ajax({
type: "POST",
url: 'increase.php',
data: {id:$(this).val()},
success: function(data) {
alert('Increased.....');
},
error: function() {
alert('Sorry! there was an issue');
}
});
}
});
in increase.php write your code to increase value in table.
Ok, so you have this :
<form ...>
<table>
<tr>
<td>
</td>
//...
<td>
<input type='checkbox' value='YOUR_ID' name='checkboxarray[]'/>
</td>
</tr>
</table>
<input name='submit' type='submit' ...>
</form>
You want that on submit, the corresponding ID database record "counter field" to be increased by 1 'IF THE BOX IS CHECKED'
then, do that :
//if you posted :
if(isset($_POST['submit'])){
//here you have to handle your data
//your checkbox array is not empty IF there is something checked, so :
if(is_array($_POST['checkboxarray'])){
foreach($_POST['checkboxarray'] as $value){
//HERE YOUR $VALUE IS THE ID OF THE DB RECORD (if you dit id the way I explain it over), so do your database stuff here, just increase your field WHERE id = $value !
}
}else{
//no checkboxes checked
}
}else{
//nothing posted, just display your form
}
Is that what you need?
Does anyone knows how to code in php for every time i tick the check-box in my form? And when i tick the check-box,the value is suppose to actually inserted into an id column in my database and it will auto increase every time i tick and submit the form.
considering your post when you say "every time i tick AND SUBMIT THE FORM", then there is no need to use javascript or ajax in your case