0

I am posting this doubt already as a last resort. I want to insert 0 or 1 into the Boolean / TINYINT. I used var_dump and I see that html always passes as False (0).

I will post part of the code of html, php and mysql. Any help will be much appreciated!

<td><input name="input_servicos[0]" id="input_servicos[0]" type="checkbox" value="1" />Acolhimento</td>
<td><input name="input_servicos[1]" id="input_servicos[1]" type="checkbox" value="1" />Atrium</td>
<td><input name="input_servicos[2]" id="input_servicos[2]" type="checkbox" value="1" />Bar</td>




if ((isset($input_servicos[0])) || (isset($input_servicos[1]))) {
                if (isset($input_servicos[0])) {
                    $input = $_POST[$input_servicos[0]];
                    $sql_input = "INSERT INTO `gestao_voluntarios`.`voluntarios` (servico_acolhimento) VALUES ('$input')";
                    $conn->query($sql_input);
                }
            }

On Html I have 36 indexes, so on php I have the too, I havent posted all the code since its pretty much the same.

Remember, the vars is boolean.

Best Regards, Helder

2
Contributors
1
Reply
30
Views
2 Years
Discussion Span
Last Post by lps
1

I modified your codes and it is working

<form method="POST">
<table>
<tr>
<td><input name="input_servicos[0]" id="input_servicos[0]" type="checkbox" value="1" />Acolhimento</td>
<td><input name="input_servicos[1]" id="input_servicos[1]" type="checkbox" value="1" />Atrium</td>
<td><input name="input_servicos[2]" id="input_servicos[2]" type="checkbox" value="1" />Bar</td>
</tr>
</table>
<input type="submit" name="submit" value="submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
    $input = array();
    for($i = 0; $i < 36; $i++){
        $input = isset($_POST['input_servicos'][$i]) ? true : false;
        $sql_input = "INSERT INTO `gestao_voluntarios`.`voluntarios` (servico_acolhimento) VALUES ('$input')";
        $conn->query($sql_input);
    }
}
?>

Or maybe the database structure having issue?

Votes + Comments
Not the neatest way of doing it... but it works, I guess.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.