J'ai quelques soucis avec mon premier script d'insertion, il me dit que ma commande est vide.
Ajouter des onglets suivant les catégories de produits, café, sandwichent, etc. valider dans une seule page ?
Merci de votre aide.
<?PHP
header('Content-type: text/html; charset=UTF-8');
$choix = filter_input(INPUT_POST, 'choix');
$table = filter_input(INPUT_POST, 'table');
$message = '';
if(!empty($choix)){
require("function.php");
$connection = connexion_db ();
foreach($choix as $liste) {
$insert_prep=array(':article'=> $liste,
':table'=> $table,
':date_enregistrement'=> date("Y-m-j H:i:s"));
$value_choix = implode(', ',array_keys($insert_prep));
$inser_exec=$connection->prepare( 'INSERT INTO commande ('.str_replace(':','',$value_choix).') VALUES('.$value_choix.')');
$inser_exec->execute($insert_prep);
}
if ($inser_exec === true)
{
header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/commande_passer.php");
}
}else { /* Au moins un choix dans la commande*/
$message = 'Passer votre commande, car elle est vide.';
}
?>
<!doctype html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style_co.css">
<title>commande</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
// Une fois le chargment de la page terminé ...
$(document).ready(function(){
// Lorsqu'un lien a.tab est cliqué
$("a.tab").click(function () {
// Mettre toutes les onglets non actif
$(".active").removeClass("active");
// Mettre l'onglet cliqué actif
$(this).addClass("active");
// Cacher les boîtes de contenu
$(".content").slideUp();
// Pour afficher la boîte de contenu associer, nous
// avons modifier le titre du lien par le nom de
// l'identifiant de la boite de contenu
var contenu_aff = $(this).attr("title");
$("#" + contenu_aff).slideDown();
});
});
</script>
</head>
<body>
<div id="commande">
<form action="#" method="post">
<fieldset>Commande<br/>
<ul class="tabs">
<li><a href="#" title="content_1" class="tab active">Café</a></li>
<li><a href="#" title="content_2" class="tab">Sandwich</a></li>
<li><a href="#" title="content_3" class="tab">Boissons fraîche</a></li>
<li><a href="#" title="content_4" class="tab">Boissons 1</a></li>
<li><a href="#" title="content_5" class="tab">Boissons 2</a></li>
<li><a href="#" title="content_6" class="tab">Boissons 3</a></li>
<li><a href="#" title="content_7" class="tab">Boissons 4</a></li>
<li><a href="#" title="content_8" class="tab">Boissons 5</a></li>
<li><a href="#" title="content_9" class="tab">Boissons 6</a></li>
<li><a href="#" title="content_10" class="tab">Boissons 7</a></li>
</ul>
</fieldset>
<div id="content_1" class="content">
<p><table width="100%">
<tr>
<td>Café noir<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /><p><input type="checkbox" name="choix[]" value="Café noir"></p></td>
<td><input type="checkbox" name="choix[]" value=""></td>
<td><input type="checkbox" name="choix[]" value=""></td>
<td><input type="checkbox" name="choix[]" value="">></td>
</tr>
<tr>
<td>Café au lait<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /><p><input type="checkbox" name="choix[]" value="Café au lait"></p></td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td>Café moka<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /><p><input type="checkbox" name="choix[]" value="Café moka"></p></td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td>Café Crème<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /><p><input type="checkbox" name="choix[]" value="Café Crème"></p></td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
</table></p>
</div>
<div id="content_2" class="content">
<p><table width="100%">
<tr>
<td><input type="checkbox" name="choix[]" value="Café noir"> Café noir<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café au lait"> Café au lait<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café moka"> Café moka<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café Crème"> Café Crème<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
</table></p>
</div>
<div id="content_3" class="content">
<p><table width="100%">
<tr>
<td><input type="checkbox" name="choix[]" value="Café noir"> Café noir<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café au lait"> Café au lait<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café moka"> Café moka<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
<td><input type="checkbox" name="choix[]" value="Café Crème"> Café Crème<img src="imdesign/tasse-a-cafe-avec-soucoupe.jpg" width="100" height="100" /></td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
<tr>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
<td><input type="checkbox" name="choix[]" value=""> </td>
</tr>
</table></p>
</div>
<div id="content_4" class="content"></div>
<div id="content_5" class="content"></div>
<div id="content_6" class="content"></div>
<div id="content_7" class="content"></div>
<div id="content_8" class="content"></div>
<div id="content_9" class="content"></div>
<div id="content_10" class="content"></div>
<p><input type="hidden" name="table" value="1" /></p>
<p><input type"submit" value="Envoyer" id ="valider"/></p>
</form>
<div id="message">
<?PHP if(!empty($message)){
echo '<div class="message" style="color:red;text-align:center;"><b>'.$message.'</b></div>';
}
?>
</div>
<br />
</div>
</body>
</html>