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 :

insertion dans la base de donnée


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2019
    Messages : 1
    Par défaut insertion dans la base de donnée
    Bonjour
    aide moi SVP
    quand je cliquer sur ajouter aucune donnée ne s'ajouter à la base

    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
    <?php
    session_start();
    require('config.php');
     
     
    ?>
    <html>
    <head>
    	<title> Ajouter une commande</title>
    	<style type="text/css">
    .container{
        box-shadow: 1px 1px 30px black;
        width:85%;
        background-color: rgb(151,199,222);
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 1%;
     
        }
            button:hover{background-color: rgb(151,199,222);}
    footer{text-align: center;margin-top: 3%; }
    body{background-color: #EEE;}
    .notifdiv{ border:1px  dotted black;text-align: center;margin-left:auto;margin-right:auto;margin-top:1%;background-color:#EEF;width:40%; }  
    .notif,span{color:red;}
    a{text-decoration: none;}
    button{
      background-color: #EEF;
      text-align: right;
      width: 170px;
      height: 6%;
      background-repeat: no-repeat;
      background-position: center left;
    }
    header{text-align: center;background-color: #EEF;}
      fieldset{background-color:#EEF;margin-top:0px;margin-left: auto;margin-right: auto; width: 40%;}
    	     .submit{text-align: center;}
    input[Value="Ajouter le clients"]{
    height: 50px;
    width: 180px;
    background-repeat: no-repeat;
    background-position: center left;
    text-align: right;
    background-image: url('add.png');
    background-color: #EEF;
    }
    .confirm{
    	text-align: center;
    	margin-top:0px; ;
    margin-bottom: 1em;
    color: ;
    border:1px solid #a2d246;
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    background-color: #ebf8a4;
    }
    	</style>
     
     
    </head>
     
     
    <?php
     
    try
    {
    $bdd = new PDO('mysql:host=localhost;dbname=gestiondestock','root','');
    }catch (Exception $e)
    {die('Erreur : ' . $e->getMessage());}
    ?>
    <?php
    if(isset($_POST['matcommande'])   && isset($_POST['datecommande'])&&  isset($_POST['client'])&& isset($_POST['produits'])
    	&& isset($_POST['quantiteachete'])&& isset($_POST['prixht'])) 
    {
    $req = $bdd->prepare('INSERT INTO commandeclient (matcommande,client,datecommande,produits,quantiteachete,prixht) 
    VALUES(:matcommande,:client,:datecommande,:produits,:quantiteachete,:prixht)');
    $req->execute(array(
    ':matcommande' => strtoupper(htmlspecialchars(trim($_POST['matcommande']))),
     
    ':datecommande' => htmlspecialchars($_POST['datecommande']),
    ':client' => ucfirst(strtolower(htmlspecialchars(trim($_POST['client'])))),
    ':produits' => ucfirst(strtolower(htmlspecialchars(trim($_POST['produits'])))),
    ':quantiteachete' => ucfirst(strtolower(htmlspecialchars(trim($_POST['quantiteachete'])))),
    ':prixht' => htmlspecialchars($_POST['prixht']),
     
    ));
    $message= " commande a bien été ajouté !";
    $req->debugDumpParams();
    }
     
    ?>
     
    <body>
    <div class="container">
    <?php include_once('header.php');?>	
    <fieldset><legend><img src="pers.png"></legend>
    	<?php if(isset($message)){?><p class="confirm"><em> <?php echo $message;}?></em></p>
    <form method="post" action="commande.php">
    	    <table border="0" cellspacing="5" >
    	<tr><td><label> réference Commande: </label></td><td><input type="text" name="matcommande" required size="30"  /></td></tr>
    	<tr><td>	<label>date commande :</label></td><td><input type="text" name="datecommande" required size="30" /></td></tr>
    	<tr><td><label>client : </label></td><td><input type="text" name="client" required size="30"  /></td></tr>
     
     
    <tr><td>	<label>produits :</label></td><td><input type="text"   name="produits" required size="30" /></td></tr>
    <tr><td>	<label>qunatité  :</label></td><td><input type="text"   name="quantiteachete" required size="30" /></td></tr>
    <tr><td>	<label>Prix unitaire :</label></td><td><input type="text"   name="prixht" required size="30" /></td></tr>
     
                    <tr><td></td></tr><tr><td></td></tr>
     
     
        <tr class="submit"><td colspan="2"><input type="submit" Value="Ajouter commande " /></tr></td>
    </table>
    </form>
    </fieldset>
    <?php include_once("footer.html");?>
    <br>
    </div> 
    </body>
    </html>

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    Tu peux commencer par activer les exceptions PDO au niveau de la connexion :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $bdd = new PDO('mysql:host=localhost;dbname=gestiondestock','root','', [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_EMULATE_PREPARES   => false
    ]);
    Tu peux aussi débugger en faisant un var_dump($_POST) histoire de voir ce que ton formulaire t'envoie.

    Au passage, il n'est pas nécessaire d'appliquer htmlspecialchars sur les données avant de faire l'insertion en base. Il vaut mieux le faire au moment de l'affichage.
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

Discussions similaires

  1. Parcours d'un fichier et insertion dans une base de données !
    Par condor_01 dans le forum Général Java
    Réponses: 2
    Dernier message: 24/04/2008, 09h24
  2. [paradox7] Problème d'insertion dans la base de données
    Par mouna201 dans le forum Bases de données
    Réponses: 4
    Dernier message: 01/02/2006, 09h47
  3. problème d'insertion dans une base de données
    Par belmansour tidjani dans le forum JDBC
    Réponses: 7
    Dernier message: 18/01/2006, 22h13
  4. [Hibernate] problème d'insertion dans la base de données
    Par Willy7901 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 18/08/2005, 13h19
  5. Probleme d'insertion dans la base de données
    Par PrinceMaster77 dans le forum ASP
    Réponses: 5
    Dernier message: 11/06/2004, 16h21

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