PHP MySQLi Insert field checkbox int

0

I'm trying to do an INSERT, but I'm not sure how to get checkbox fields.

THE TABLES ARE CREATED SO:

  

works tinyint (1)

     

contract tinyint (1)

Using php 7.

$inserir = $conexao->query("INSERT INTO cadastro (nome, sobrenome, email, senha, contratar, trabalhar) VALUES (
          $_POST[nome],
          $_POST[sobrenome],
          $_POST[email],
          $_POST[senha],
          $_POST[contratar],
          $_POST[trabalhar]
");

HTML

<div class="container">
    <form class="form-horizontal bg-cinza rounded col-sm-6 col-md-8 col-12 mx-auto row-margem" role="form" method="POST" action="cadastro.php">
        <div class="row">
            <div class="col-md-12">
                <h2 class="espaco20 centro">Faça seu cadastro gratuitamente</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                        <div class="input-group-addon" style="width: 2.6rem"><i class="fa fa-user"></i></div>
                        <input type="text" name="nome" class="form-control form-control-md" id="name" value="" placeholder="Nome" required autofocus>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                        <div class="input-group-addon" style="width: 2.6rem"><i class="fa fa-user"></i></div>
                        <input type="text" name="sobrenome" class="form-control form-control-md" id="sobrenome" value="" placeholder="Sobrenome" required autofocus>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                        <div class="input-group-addon" style="width: 2.6rem"><i class="fa fa-at"></i></div>
                        <input type="text" name="email" class="form-control form-control-md" id="email" value="" placeholder="E-mail" required autofocus>
                    </div>
                </div>
            </div>
        </div>

        <div class="row espaco20">
            <div class="col-md-12">
                <div class="form-group">
                    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                        <div class="input-group-addon" style="width: 2.6rem"><i class="fa fa-key"></i></div>
                        <input type="password" name="senha" class="form-control form-control-md" id="senha" value="" placeholder="Password" required>
                    </div>
                </div>
            </div>
        </div>

        <p>Você deseja:</p>
        <label class="custom-control custom-checkbox">
            <input id="radio1" name="contratar" type="checkbox" class="custom-control-input">
            <span class="custom-control-indicator"></span>
            <span class="custom-control-description">Contratar</span>
        </label>
        <label class="custom-control custom-checkbox espaco20">
            <input id="radio2" name="trabalhar" type="checkbox" class="custom-control-input">
            <span class="custom-control-indicator"></span>
            <span class="custom-control-description">Trabalhar</span>
        </label>

        <div class="row espaco50">
            <div class="col-md-12">
                <button type="submit" class="btn btn-success" id="cadastro"><i class="fa fa-user-plus"></i> Register</button>
            </div>
        </div>



        <input type="hidden" name="form" value="form">
    </form>


</div>
    
asked by anonymous 23.07.2017 / 02:03

1 answer

0

You need to set the value of the input: radius and input: checkbox with something like value="1" or value="true".

<input type="checkbox" name="test" value="1">

To receive the value after submitting you do the same way you used in your code above.

    
23.07.2017 / 02:48