将输入复选框值存储到MySQL数据库中

时间:2015-02-16 15:00:54

标签: php mysql forms checkbox

即使经过对stackOverflow的广泛研究,我目前还没有找到解决问题的方法。

基本上,我有多个输入复选框,当用户点击" OK"时,这些值存储在特定的MYSQL数据库中。我设法存储了所有内容,文本输入,电话,日期等,但没有存储复选框值!在MYSQL中," jeux"设置为varchar(256)。我的错误:

Error: INSERT INTO donnees (nom, prenom, adresse, tel, email, adresse2, date, nb_invite, evenement, jeux) VALUES ('hergiuyer', 'rsthrsr', 'tnrhdsh', 'rsthnrs', 'rtsnhtdyhjr', 'ntherjhtyg', 'hzrhedr', 'hrersjher', 'rjhedtjher', 'Chuck-à-Luck, Roulette, Stud Poker')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'edr', 'hre(rsjher', 'rjhedtjher', 'Chuck-à-Luck, Roulette, Stud Poker')' at line 2

我如何存储它们?

vos_jeux.php

<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>

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']);

mysql_query("SET NAMES UTF8");

$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);
?>

0 个答案:

没有答案