Join multiple PDO BINDPARAM checkboxes

Asked

Viewed 19 times

0

I have a long form beyond the normal data, name, Evil and so on, I have 129 checkboxs, with a script that limits the choice of 3 checkboxs, and I want the 3 checkboxs chosen, are all inserted in the same field of the database ( Categories )

Follow the code

$dados = filter_input_array(INPUT_POST, FILTER_DEFAULT);

if (!empty($dados['AddCar'])) {



    $query_carro = "INSERT INTO formularioprofissionais (nome, codigopostal, cidade, localizacao, telefone, email,
     assosiation, shortdesc, year1, production1, type1, producer1, position1, link1, year2, production2, type2, producer2, position2, link2,
   year3, production3, type3, producer3, position3, link3, year4, production4, type4, producer4, position4, link4,
 year5, production5, type5, producer5, position5, link5)
                VALUES (:nome, :codigopostal, :cidade, :localizacao, :telefone, :email,
    :assosiation, :shortdesc, :year1, :production1, :type1, :producer1, :position1, :link1, :year2, :production2, :type2, :producer2, :position2, :link2,
    :year3, :production3, :type3, :producer3, :position3, :link3, :year4, :production4, :type4, :producer4, :position4, :link4,
 :year5, :production5, :type5, :producer5, :position1, :link5)";
    $cad_carro = $conn->prepare($query_carro);
    $cad_carro->bindParam(':nome', $dados['nome'], PDO::PARAM_STR);
    $cad_carro->bindParam(':codigopostal', $dados['codigopostal'], PDO::PARAM_STR);
    $cad_carro->bindParam(':cidade', $dados['cidade'], PDO::PARAM_STR);
    $cad_carro->bindParam(':localizacao', $dados['localizacao'], PDO::PARAM_STR);
    $cad_carro->bindParam(':telefone', $dados['telefone'], PDO::PARAM_STR);
    $cad_carro->bindParam(':email', $dados['email'], PDO::PARAM_STR);
    $cad_carro->bindParam(':assosiation', $dados['assosiation'], PDO::PARAM_STR);
    $cad_carro->bindParam(':shortdesc', $dados['shortdesc'], PDO::PARAM_STR);
    $cad_carro->bindParam(':year1', $dados['year1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':production1', $dados['production1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':type1', $dados['type1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':producer1', $dados['producer1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':position1', $dados['position1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':link1', $dados['link1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':year2', $dados['year2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':production2', $dados['production2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':type2', $dados['type2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':producer2', $dados['producer2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':position2', $dados['position2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':link2', $dados['link2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':year3', $dados['year3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':production3', $dados['production3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':type3', $dados['type3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':producer3', $dados['producer3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':position3', $dados['position3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':link3', $dados['link3'], PDO::PARAM_STR);
    $cad_carro->bindParam(':year4', $dados['year4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':production4', $dados['production4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':type4', $dados['type4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':producer4', $dados['producer4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':position4', $dados['position4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':link4', $dados['link4'], PDO::PARAM_STR);
    $cad_carro->bindParam(':year5', $dados['year5'], PDO::PARAM_STR);
    $cad_carro->bindParam(':production5', $dados['production5'], PDO::PARAM_STR);
    $cad_carro->bindParam(':type5', $dados['type5'], PDO::PARAM_STR);
    $cad_carro->bindParam(':producer5', $dados['producer5'], PDO::PARAM_STR);
    $cad_carro->bindParam(':position5', $dados['position5'], PDO::PARAM_STR);
    $cad_carro->bindParam(':link5', $dados['link5'], PDO::PARAM_STR);
/*    $cad_carro->bindParam(':checkbox1', $dados['checkbox1'], PDO::PARAM_STR);
    $cad_carro->bindParam(':checkbox2', $dados['checkbox2'], PDO::PARAM_STR);
    $cad_carro->bindParam(':categorias', $dados['categorias'], PDO::PARAM_STR);

    $categorias = $checkbox1 . ' ' . $checkbox2;
*/

    $cad_carro->execute();

/*    $categorias = array_combine($_POST['checkbox1'],$_POST['checkbox2'],$_POST['checkbox3'],$_POST['checkbox4']); */



    if($cad_carro->rowCount()){
        echo "Sucesso!<br>";
    }else{
        echo "Erro<br>";
    }
}
?>

<form name="adqdasdasd-car" method="POST" action="">
    <input type="text" name="nome" class="formularioprof formularioproofmax" name="nome" placeholder="<?php echo $lang['formnome']?>"/>
    <input type="text" name="codigopostal" class="formularioprof"  placeholder="<?php echo $lang['formcodigopostal']?>"/>


      <input type="text" class="formularioprof" name="cidade" placeholder="<?php echo $lang['formcidade']?>"/>
      <input type="text" class="formularioprof" name="localizacao" placeholder="<?php echo $lang['formlocalidade']?>"/>
      <input type="text" class="formularioprof" name="telefone" placeholder="<?php echo $lang['formtelefone']?>"/>
      <input type="text" class="formularioprof" name="email" placeholder="<?php echo $lang['formemail']?>"/>
      <input type="text" class="formularioprof" name="assosiation" placeholder="<?php echo $lang['formassociation']?>"/>
      <div class="form-outline ">
        <textarea class="formdesc formularioprof" name="shortdesc"  placeholder="<?php echo $lang['formshortdesc']?>" id="textAreaExample" rows="4"></textarea>
      </div><h2 style="color:#ffca55 !important; line-height:1; padding-top:50px;" class="font80px"><?php echo $lang['formtitulos2']?></h2>
      <h2 style="color:#ffca55 !important; line-height:1;  font-size:18px; padding-top:20px;  padding-bottom:3px;"><?php echo $lang['production1']?></h2>

        <input type="text" class="formularioprof" name="year1" placeholder="<?php echo $lang['formyear']?>"/>
        <input type="text" class="formularioprof" name="production1"  placeholder="<?php echo $lang['formproductiontittle']?>"/>
        <input type="text" class="formularioprof" name="type1" placeholder="<?php echo $lang['formfilm']?>"/>
        <input type="text" class="formularioprof" name="producer1" placeholder="<?php echo $lang['formproducer']?>"/>
        <input type="text" class="formularioprof" name="position1" placeholder="<?php echo $lang['formposition']?>"/>
        <input type="text" class="formularioprof" name="link1" placeholder="<?php echo $lang['formlink']?>"/>
      <p style="border-bottom:1px solid #a3a3a3; width:1072px;height:30px;"></p>
      <h2 style="color:#ffca55 !important; line-height:1;  font-size:18px; padding-top:20px; padding-bottom:3px;"><?php echo $lang['production2']?></h2>

      <input type="text" class="formularioprof" name="year2" placeholder="<?php echo $lang['formyear']?>"/>
      <input type="text" class="formularioprof" name="production2"  placeholder="<?php echo $lang['formproductiontittle']?>"/>
      <input type="text" class="formularioprof" name="type2" placeholder="<?php echo $lang['formfilm']?>"/>
      <input type="text" class="formularioprof" name="producer2" placeholder="<?php echo $lang['formproducer']?>"/>
      <input type="text" class="formularioprof" name="position2" placeholder="<?php echo $lang['formposition']?>"/>
      <input type="text" class="formularioprof" name="link2" placeholder="<?php echo $lang['formlink']?>"/>
          <p style="border-bottom:1px solid #a3a3a3; width:1072px;height:30px;"></p>
          <h2 style="color:#ffca55 !important; line-height:1;  font-size:18px; padding-top:20px; padding-bottom:3px;"><?php echo $lang['production3']?></h2>

          <input type="text" type="text" class="formularioprof" name="year3" placeholder="<?php echo $lang['formyear']?>"/>
          <input type="text" class="formularioprof" name="production3"  placeholder="<?php echo $lang['formproductiontittle']?>"/>
          <input type="text" class="formularioprof" name="type3" placeholder="<?php echo $lang['formfilm']?>"/>
          <input type="text" class="formularioprof" name="producer3" placeholder="<?php echo $lang['formproducer']?>"/>
          <input type="text" class="formularioprof" name="position3" placeholder="<?php echo $lang['formposition']?>"/>
          <input type="text" class="formularioprof" name="link3" placeholder="<?php echo $lang['formlink']?>"/>
          <p style="border-bottom:1px solid #a3a3a3; width:1072px;height:30px;"></p>
          <h2 style="color:#ffca55 !important; line-height:1;  font-size:18px; padding-top:20px; padding-bottom:3px;"><?php echo $lang['production4']?></h2>

          <input type="text" class="formularioprof" name="year4" placeholder="<?php echo $lang['formyear']?>"/>
          <input type="text" class="formularioprof" name="production4"  placeholder="<?php echo $lang['formproductiontittle']?>"/>
          <input type="text" class="formularioprof" name="type4" placeholder="<?php echo $lang['formfilm']?>"/>
          <input type="text" class="formularioprof" name="producer4" placeholder="<?php echo $lang['formproducer']?>"/>
          <input type="text" class="formularioprof" name="position4" placeholder="<?php echo $lang['formposition']?>"/>
          <input type="text" class="formularioprof" name="link4" placeholder="<?php echo $lang['formlink']?>"/>
            <p style="border-bottom:1px solid #a3a3a3; width:1072px;height:30px;"></p>
            <h2 style="color:#ffca55 !important; line-height:1;  font-size:18px; padding-top:20px;  padding-bottom:3px;"><?php echo $lang['production5']?></h2>

            <input type="text" class="formularioprof" name="year5" placeholder="<?php echo $lang['formyear']?>"/>
            <input type="text" class="formularioprof" name="production5"  placeholder="<?php echo $lang['formproductiontittle']?>"/>
            <input type="text" class="formularioprof" name="type5" placeholder="<?php echo $lang['formfilm']?>"/>
            <input type="text" class="formularioprof" name="producer5" placeholder="<?php echo $lang['formproducer']?>"/>
            <input type="text" class="formularioprof" name="position5" placeholder="<?php echo $lang['formposition']?>"/>
            <input type="text" class="formularioprof" name="link5" placeholder="<?php echo $lang['formlink']?>"/>

            <label class="containerform"><?php echo $lang['optionprof1']?><input type="checkbox" class="single-checkbox"  name="checkbox1" value="<?php echo $lang['optionprof1']?>"> <span class="checkmark"></span></label>
            <label class="containerform"><?php echo $lang['optionprof2']?><input type="checkbox" class="single-checkbox" name="checkbox2"  value="<?php echo $lang['optionprof2']?>"> <span class="checkmark"></span></label>
            <label class="containerform"><?php echo $lang['optionprof3']?><input type="checkbox" class="single-checkbox" name="checkbox3"  value="<?php echo $lang['optionprof3']?>"> <span class="checkmark"></span></label>
            <label class="containerform"><?php echo $lang['optionprof4']?><input type="checkbox" class="single-checkbox" name="checkbox4"  value="<?php echo $lang['optionprof4']?>"> <span class="checkmark"></span></label>

    <input type="submit" value="Cadastrar" name="AddCar">
</form>

Note: There are only 4 checkboxs, the other 125 I will add, when I realize how the code works, I will add the remaining checkboxs, already tested several codes like this

$categorias = (is_array($_POST['categoriask'])) ? $_POST['categoriask'] : [];
    $categorias_string = implode(',', $categorias);

Where the "categoriask" corresponded to the

I’ve tested with others I’ve found, but they haven’t worked, and I’m not finding many solutions.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.