I want to store basic user input into a database via INSERT INTO. I've managed to store all input possible (text, tel...) but checkboxes is a problem as they are arrays! How can I store them?
vos_jeux.php (where checkboxes are displayed)
<form method="post" action="end.php">
<p>
Cochez les jeux désirés pour votre soirée:<br>
<label for="blackjack"><img src="img/blackjack.jpg" alt=""></label>
<INPUT id="blackjack" type="checkbox" name="game[]" value="Blackjack">
<label for="chuckaluck"><img src="img/chuckaluck.jpg" alt=""></label>
<INPUT id="chuckaluck" type="checkbox" name="game[]" value="Chuck à Luck">
<label for="roulette"><img src="img/roulette.jpg" alt=""></label>
<INPUT id="roulette" type="checkbox" name="game[]" value="Roulette">
<label for="stud"><img src="img/stud.jpg" alt=""></label>
<INPUT id="stud" type="checkbox" name="game[]" value="Stud Poker">
<label for="holdem"><img src="img/holdem.jpg" alt=""></label>
<INPUT id="holdem" type="checkbox" name="game[]" value="Holdem Poker">
<label for="boule"><img src="img/boule.jpg" alt=""></label>
<INPUT id="boule" type="checkbox" name="game[]" value="La Boule">
<input type="button" value="Retour en arrière" onClick="self.history.back();">
<input type="submit" name="submit" value="Poursuivre">
</p>
</form>
Look at my database: (see how "jeux" checkboxes don't appear)
end.php
<?php
include "connect.php";
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$adresse = $_POST['adresse'];
$tel = $_POST['tel'];
$mail = $_POST['mail'];
$adresse2 = $_POST['adresse2'];
$date = $_POST['date'];
$nb_invite = $_POST['nb_invite'];
$evenement = $_POST['evenement'];
$game = implode(',', $_POST['game']);
$sql = "INSERT INTO donnees (nom, prenom, adresse, tel, email, adresse2, date, nb_invite, evenement, jeux)
VALUES ('$nom', '$prenom', '$adresse', '$tel', '$mail', '$adresse2', '$date', '$nb_invite', '$evenement', '$game')";
if (mysqli_query($conn, $sql)) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
1_ I tried the "implode" solution but it doesn't seem to work. What can I do? 2_ Echoing the $sql variable gives: INSERT INTO donnees (nom, prenom, adresse, tel, email, adresse2, date, nb_invite, evenement, jeux) VALUES ('foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', '')
The results of the checkbox inputs is NULL '' ! Why?
Aucun commentaire:
Enregistrer un commentaire