so I attempt to insert the values of my checkbox into my database but I can't.. Can you help me please ?
This is the PHP Code
<?php
if(empty($_POST["choix"]))
{
echo "Il faut préciser le type d'abonnement";
}
else{
include "connectBdd.php";
try {
$sql="INSERT into abonee(nomabo,prenomabo,villeabo, adressmail_abo,adress_abo,abotel,codepostalbo) values(:nom,:prenom,:ville,:mail,:perso,:tel,:code)";
$resultat = $cnx->prepare($sql);
$nbLignes= $resultat->execute(array(":nom"=> $_POST["nom"],
":ville"=> $_POST["ville"],
":mail"=> $_POST["mail"],
":perso"=> $_POST["perso"],
":tel"=> $_POST["numero"],
":code"=> $_POST["code"],
":typeAbo"=>$_POST["choix"])
":prenom"=> $_POST["prenom"]));
echo $nbLignes." ligne ajoutée";
}
catch(PDOException $e) { // gestion des erreurs
echo"ERREUR dans l'ajout ".$e->getMessage();
}
}
?>
The problem here is that I generally use a foreach loop to extract the values of a checkbox but in this situation I can't because we are in a declaration of a array
Thank you everyone !
Edit : this is the content of my $_POST
array(9) { ["choix"]=> array(2) { [0]=> string(15) "Abonnée Papier" [1]=> string(19) "Abonnée numérique" } ["Don"]=> string(2) "ab" ["prenom"]=> string(10) "first name" ["nom"]=> string(10) " last name" ["ville"]=> string(4) " Usa" ["mail"]=> string(0) "" ["perso"]=> string(16) " blabla@gmai.com" ["code"]=> string(3) "123" ["numero"]=> string(3) "156" }
I can post the HTML form too in order to understand ?