par
Lays » 28 nov. 2010, 07:51
Voici, si sa peut t'aider :
Si une checkbox est coché, elle se post comme élément avec une value "on" je crois dans ton $_POST, si elle n'est pas coché, elle ne s'envoie simplement pas...
Pour les radio button, t'as X radios button avec la meme valeur, chacun a une "value" donc elle envoie une value (celle qui est sélectionné)
<?php
if(isset($_POST['hidSubmit'])) {
$conn = mysql_connect("TonServeur", "TonUsername", "TonPassword") or die("Connection BDD Impossible : " . mysql_error());
mysql_select_db("TaBDD", $conn) or die(mysql_error());
$check1 = (int)isset($_POST['check1']); //Renvoie 0 si le checkbox n'a pas été coché et 1 si il a été coché
$check2 = (int)isset($_POST['check2']); //Same thing
$radio = (int)$_POST['radio']; //ici $radio vaut soit 1 ou 2 -> on le convertit en integer puisqu'on sait que ça doit être nécessairement un chiffre
//On fait des validations de sécurité
if($radio > 2 || $radio < 1) {
echo "Méchant garçon !";
} else {
$insertQ = "INSERT INTO ttable(check1, check2, radio) VALUES($check1, $check2, $radio)";
if(mysql_query($insertQ, $conn)) {
echo "Insertion BDD Réussi !";
} else { die(mysql_error()); }
}
}
?>
et un petit formulaire HTML
<form action="" method="post">
<div style="margin-bottom:10px;">
<label for="check1">Check1 : </label><input type="checkbox" name="check1" id="check1" />
<label for="check2">Check2 : </label><input type="checkbox" name="check2" id="check2" />
</div>
<div>
<label for="radio1">Radio1 : </label><input type="radio" name="radio1" id="radio1" value="1" />
<label for="radio2">Radio2 : </label><input type="checkbox" name="radio1" id="radio2" value="2" />
</div>
<input type="submit" value="Envoyer" name="hidSubmit" />
</form>
Voici, si sa peut t'aider :
Si une checkbox est coché, elle se post comme élément avec une value "on" je crois dans ton $_POST, si elle n'est pas coché, elle ne s'envoie simplement pas...
Pour les radio button, t'as X radios button avec la meme valeur, chacun a une "value" donc elle envoie une value (celle qui est sélectionné)
[php]
<?php
if(isset($_POST['hidSubmit'])) {
$conn = mysql_connect("TonServeur", "TonUsername", "TonPassword") or die("Connection BDD Impossible : " . mysql_error());
mysql_select_db("TaBDD", $conn) or die(mysql_error());
$check1 = (int)isset($_POST['check1']); //Renvoie 0 si le checkbox n'a pas été coché et 1 si il a été coché
$check2 = (int)isset($_POST['check2']); //Same thing
$radio = (int)$_POST['radio']; //ici $radio vaut soit 1 ou 2 -> on le convertit en integer puisqu'on sait que ça doit être nécessairement un chiffre
//On fait des validations de sécurité
if($radio > 2 || $radio < 1) {
echo "Méchant garçon !";
} else {
$insertQ = "INSERT INTO ttable(check1, check2, radio) VALUES($check1, $check2, $radio)";
if(mysql_query($insertQ, $conn)) {
echo "Insertion BDD Réussi !";
} else { die(mysql_error()); }
}
}
?>
[/php]
et un petit formulaire HTML
[html]<form action="" method="post">
<div style="margin-bottom:10px;">
<label for="check1">Check1 : </label><input type="checkbox" name="check1" id="check1" />
<label for="check2">Check2 : </label><input type="checkbox" name="check2" id="check2" />
</div>
<div>
<label for="radio1">Radio1 : </label><input type="radio" name="radio1" id="radio1" value="1" />
<label for="radio2">Radio2 : </label><input type="checkbox" name="radio1" id="radio2" value="2" />
</div>
<input type="submit" value="Envoyer" name="hidSubmit" />
</form>[/html]