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 :

Insert Session dans BDD


Sujet :

PHP & Base de données

Vue hybride

ishaq74 Insert Session dans BDD 03/04/2020, 13h11
solo190 hello ishaq74 , dans ta... 14/04/2020, 08h52
Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Actif ouais
    Inscrit en
    Septembre 2017
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Actif ouais

    Informations forums :
    Inscription : Septembre 2017
    Messages : 45
    Par défaut Insert Session dans BDD
    Bonjour,

    J'ai un problème pour insérer la commande dans sql quand le panier est validé :

    Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
    	foreach($_SESSION["shopping_cart"] as $keys => $values)
    	{
    			echo "<tr><td>".$values["product_quantity"]."</td>";
    			echo "<td>".$values["product_name"]."</td>";
    			echo "<td>".number_format($values["product_price"] * $values["product_quantity"], 2)."</td></tr>";
     
    			$total_price = $total_price + ($values["product_quantity"] * $values["product_price"]);
    			$total_item = $total_item + ($values["product_quantity"]);
    	}
    	echo "<tr> <td></td><td></td><td align='center'><br>Total : ".number_format($total_price, 2)."</td></tr>";
    ?>

    J'ai une table Commande

    idcommande, datecommande, jourcommande, numerocommande, delaicommande, etatcommande, payecommande, nomcommande, telcommande, adressecommande, villecommande

    et une table lignecommande.

    idlignecommande, idcommande, ligneproduit, lignequantite, ligneprix


    J'étais parti sur un truc du genre :

    Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     'INSERT INTO commande (datecommande, jourcommande,	numerocommande,	delaicommande, etatcommande, payecommande, nomcommande,	telcommande, adressecommande, villecommande)
    VALUES ("datecommande", "jourcommande",	"numerocommande", "delaicommande", "etatcommande", "payecommande", "nomcommande",	"telcommande", "adressecommande", "villecommande");
     SET @a = LAST_INSERT_idcommande();
    	INSERT INTO details_commande (idcommande, ligneproduit, lignequantite, ligneprix)
    VALUES ("@a","ligneproduit","lignequantite","ligneprix")';

    Mais quand je prépare ma requete, cela ne fonctionne pas du tout.

    Code PHP : 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
      require_once('dbconn.php');
      $result = 0;
     
      $datecommande  = trim($_POST["datecommande"]);
      $numerocommande  = trim($_POST["numerocommande"]);
      $delaicommande  = trim($_POST["delaicommande"]);
      $etatcommande  = trim($_POST["etatcommande"]);
      $payecommande  = trim($_POST["payecommande"]);
      $nomcommande  = trim($_POST["nomcommande"]);
      $telcommande  = trim($_POST["telcommande"]);
      $adressecommande    = trim($_POST["adressecommande"]);
      $villecommande = trim($_POST["villecommande]);
    //prepare sql and bind parameters
       $stmt = $dbconn->prepare("INSERT INTO commande(datecommande, jourcommande,	numerocommande,	delaicommande, etatcommande, payecommande, nomcommande,	telcommande, adressecommande, villecommande) VALUES (:datecommande, :jourcommande, :numerocommande, :delaicommande,:etatcommande, :payecommande, :nomcommande,	:telcommande, :adressecommande, :villecommande)");
     
        $stmt->bindParam(':datecommande', $datecommande);
    	$stmt->bindParam(':numerocommande', $numerocommande);
    	$stmt->bindParam(':delaicommande', $delaicommande);
    	$stmt->bindParam(':etatcommande', $etatcommande);
    	$stmt->bindParam(':payecommande', $payecommande);
    	$stmt->bindParam(':nomcommande', $nomcommande);
    	$stmt->bindParam(':telcommande', $telcommande);
    	$stmt->bindParam(':adressecommande', $adressecommande);
    	$stmt->bindParam(':villecommande', $villecommande);
        // insert a row
        if($stmt->execute()){
          $result =1;
        }
        echo $result;

    Merci,

  2. #2
    Membre éclairé Avatar de solo190
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Avril 2007
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 412
    Par défaut
    hello ishaq74 ,
    dans ta requête préparé , corrige ceci
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    $villecommande = trim($_POST["villecommande"]);
    A+

Discussions similaires

  1. [MySQL] Problème d'affichage malgré insertion réussie dans BDD
    Par Akushiro dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 06/07/2009, 14h30
  2. insert into dans BDD a partir d un fichier csv
    Par btsgreta77 dans le forum JDBC
    Réponses: 3
    Dernier message: 22/04/2009, 15h18
  3. [MySQL] insertion données dans BDD via formulaire
    Par stefanelle dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 23/02/2009, 10h51
  4. [MySQL] Insertion multiple dans BDD MySQL
    Par popovitch130 dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 10/08/2008, 13h38
  5. insertion log dans BDD
    Par jmjmjm dans le forum C++
    Réponses: 2
    Dernier message: 28/04/2008, 08h38

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