lundi 9 mai 2022

How do I insert multiple checkbox values into a data base with PHP ( PDO)?

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 !




Aucun commentaire:

Enregistrer un commentaire