IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Script commande online


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut Script commande online
    Bonjour, suis à la demande de ma belle-fille qui tient un petit commerce de restauration. elle m'a demandé de créer un style de menu qui tourne via intranet.

    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.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    <?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>
    		</ul>   
        </fieldset>
    <div id="content_1" class="content">
    <p><table width="100%">
      <tr>
        <td><input type="checkbox" name="choix[]" value="Café noir">&nbsp;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">&nbsp;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">&nbsp;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">&nbsp;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="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</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">&nbsp;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">&nbsp;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">&nbsp;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">&nbsp;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="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</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">&nbsp;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">&nbsp;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">&nbsp;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">&nbsp;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="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
        <td><input type="checkbox" name="choix[]" value="">&nbsp;</td>
      </tr>
    </table></p>
    </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>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Il ne faut pas avoir peur de debuguer.
    Tu peux facilement voir que c'est ton filter_input() sur le tableau "choix" qui pose problème.
    Ce filtre ne sert de toute façon à rien puisque tu n'as pas indiqué de type de filtrage.

    Egalement il manque le = sur le "type" du bouton submit.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Bonjour Sabotage merci d'abord de ta réponse rapide, le bouton ok, il reste me reste toujours le message passer votre commande, qui reste afficher j'ai un souci dans mon contrôle du champ vide .
    Le souci je vois par ou?

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    C'est ce que je t'explique dans mon message non ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Re Sabotage j'ai fait les modifications j'ai retiré le filtre et même essayé de modifier mon test champ vide mais toujours la même erreur

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Tu as bien mis
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(!empty($_POST['choix'])){
    ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Bonjour sabotage, j'ai trouvé la solution mais j'ai une autre erreur dans l'insertion dans ma table.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    <?PHP
    header('Content-type: text/html; charset=UTF-8');
     
    if(isset($_POST['choix'],$_POST['table'])){ 
      if(!empty($_POST['choix'])){ 
     
            require("function.php");
            $connection = connexion_db ();
     
                $table = $_POST['table'];
     			foreach($_POST['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.';
      }
    }
    ?>
    Erreur
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 Erreur de syntaxe près de 'table, date_enregistrement) VALUES('Café noir', '1', '2016-04-15 17:26:36')' à la ligne 1' in C:\Program Files\EasyPHP-5.3.8.1\www\shoponline\index.php:17 Stack trace: #0 C:\Program Files\EasyPHP-5.3.8.1\www\shoponline\index.php(17): PDOStatement->execute(Array) #1 {main} thrown in C:\Program Files\EasyPHP-5.3.8.1\www\shoponline\index.php on line 17

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Est-ce que tu n'aurais pas $table qui vaut 'table' par hasard ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Merci sabotage en effet j'ai changer dans ma table :-)
    encore une autre question avec implode je devrais pas avoir un ID pour toute mais choix en une ligne dans la table commande

  10. #10
    Membre régulier
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    514
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2004
    Messages : 514
    Points : 107
    Points
    107
    Par défaut
    Encore un grand merci pour ton aide sabotage, j'ai rajouté une table choix ;-)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/01/2008, 14h02
  2. Réponses: 5
    Dernier message: 06/08/2007, 13h12
  3. Différence script / commande
    Par Deaf dans le forum Shell et commandes GNU
    Réponses: 5
    Dernier message: 23/06/2007, 17h48
  4. [Script] Commande pour ajouter un favoris reseau
    Par Oui-Oui MB dans le forum Autres Logiciels
    Réponses: 5
    Dernier message: 07/03/2006, 14h42
  5. [ASE 12.5.1] Execution de scripts / commandes shell
    Par zayro dans le forum Adaptive Server Enterprise
    Réponses: 4
    Dernier message: 24/02/2006, 10h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo