1
I have a student registration form. It is all ready, the only thing I’m having difficulties is to return the value of a checkbox, which in the register refers to the student being active or not.
On the form he’s like this:
<label>Ativo</label>
<input type="checkbox" id="ativo" name="disponivel" value="ativo">
In ajax I take the value of it
$.ajax({
method: 'POST',
url: 'ajax/cadastraAluno.php',
data: {
// outros dados
ativo: $("#ativo").is(':checked')
},
In the registration fileAluno.php I use the submitted form data to record the student in the table.
cadastraAluno.php
$ativo = $_POST['ativo'];
if($ativo == true){
$codativo = '1';
} else {
$codativo = '0';
}
I can register all other data normally, except this checkbox.
In the bank, the column recording this data is "tinyint(1)"
To me it is indifferent how it will be on the bench, it can be int, Boolean, anything, as long as I can differentiate with the data, if the student is active or not.
If in the comic book you have
tinyint
then you must pass a number and not a string. Try to take this if/Else and put it like this:$codativo = $ativo ? 1 : 0;
. Worked?– Sergio