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 :

code et bdd qui fonctionne mal [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut code et bdd qui fonctionne mal
    bonsoir,ma bdd en local me fait des choses bizarres,j'explique,je rentre des données plusieurs fois,sa fonctionne mais au bout d'un moment il me change tout pour mettre la dernière entrée.Le code inscrit bien les donnée mais l'update ne fonctionne pas,je vous met le code et la bdd

    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
     $query=$db->prepare('SELECT prix_jeu_neuf,
    	                            prix_console_neuf,prix_manga_neuf,prix_figurine_neuf,prix_dvd_neuf,
    	                            stock_jeu_neuf,stock_console_neuf,stock_manga_neuf,stock_figurine_neuf,stock_dvd_neuf
                                                                                                            FROM magasin
    						                                                                                WHERE prix_jeu_neuf = :prix_jeu_neuf
    						                                                                                ');
         $query->bindValue(':prix_jeu_neuf',$prix_jeu_neuf, PDO::PARAM_STR);
         $query->execute() or die(print_r($query->errorInfo()));
         $data=$query->fetch();
     
      if($data['prix_jeu_neuf']!=$_POST['prix_jeu_neuf'] AND $data['prix_console_neuf']!= $_POST['prix_console_neuf'] AND $data['prix_manga_neuf']!= $_POST['prix_manga_neuf']
    AND $data['prix_figurine_neuf']!= $_POST['prix_figurine_neuf'] AND $data['stock_jeu_neuf']!= $_POST['stock_jeu_neuf'] AND $data['stock_console_neuf']!= $_POST['stock_console_neuf']
    AND $data['stock_manga_neuf']!= $_POST['stock_manga_neuf'] AND $data['stock_figurine_neuf']!= $_POST['stock_figurine_neuf'])
     
     
     
    	 {
     
     
        $query = $db->prepare('UPDATE magasin
     
    							              SET 
    										      prix_jeu_neuf = :prix_jeu_neuf,
    							                  prix_console_neuf = :prix_console_neuf,
    							                  prix_manga_neuf = :prix_manga_neuf,
    										      prix_figurine_neuf =:prix_figurine_neuf,
    											  prix_dvd_neuf = :prix_dvd_neuf,
    									          stock_jeu_neuf = :stock_jeu_neuf,
    							                  stock_console_neuf = :stock_console_neuf,
    							                  stock_manga_neuf = :stock_manga_neuf,
    							                  stock_figurine_neuf = :stock_figurine_neuf,
    											  stock_dvd_neuf = :stock_dvd_neuf
     
    									    WHERE id 
    							            ');
     
     
     
     
     
     
        $query->bindvalue(':prix_jeu_neuf', $prix_jeu_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':prix_console_neuf', $prix_console_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':prix_manga_neuf', $prix_manga_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':prix_figurine_neuf', $prix_figurine_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':prix_dvd_neuf', $prix_figurine_neuf, pdo::PARAM_INT);
     
    	$query->bindvalue(':stock_jeu_neuf', $stock_jeu_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':stock_console_neuf', $stock_console_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':stock_manga_neuf', $stock_manga_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':stock_figurine_neuf', $stock_figurine_neuf, pdo::PARAM_INT);
    	$query->bindvalue(':stock_dvd_neuf', $prix_figurine_neuf, pdo::PARAM_INT);
     
    	$query->execute() or die(print_r($db->errorinfo()));
    	 $query->CloseCursor();
     
     
     }else{
            $nomimage=(!empty($_FILES['image']['size']))?move_image($_FILES['image']):''; 
     
            $query=$db->prepare('INSERT INTO magasin   
    		                                          (jeu_neuf,console_neuf,manga_neuf,figurine_neuf,dvd_neuf,image,
    												  prix_jeu_neuf,prix_console_neuf,prix_manga_neuf,prix_figurine_neuf,prix_dvd_neuf,
    												  stock_jeu_neuf,stock_console_neuf,stock_manga_neuf,stock_figurine_neuf,stock_dvd_neuf)
     
                                               VALUES (:jeu_neuf,:console_neuf,:manga_neuf,:figurine_neuf,:dvd_neuf,:nomimage,
    												   :prix_jeu_neuf,:prix_console_neuf,:prix_manga_neuf,:prix_figurine_neuf,:prix_dvd_neuf,
    												   :stock_jeu_neuf,:stock_console_neuf,:stock_manga_neuf,:stock_figurine_neuf,:stock_dvd_neuf
    												   )');
     
    	$query->bindValue(':jeu_neuf', $jeu_neuf, PDO::PARAM_STR);
    	$query->bindValue(':console_neuf', $console_neuf, PDO::PARAM_STR);
    	$query->bindValue(':manga_neuf', $manga_neuf, PDO::PARAM_STR);
    	$query->bindValue(':figurine_neuf', $figurine_neuf, PDO::PARAM_STR);
    	$query->bindValue(':dvd_neuf', $dvd_neuf, PDO::PARAM_STR);
     
    	$query->bindValue(':prix_jeu_neuf', $prix_jeu_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_console_neuf', $prix_console_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_manga_neuf', $prix_manga_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_figurine_neuf', $prix_figurine_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_dvd_neuf', $prix_dvd_neuf, PDO::PARAM_INT);
     
    	$query->bindValue(':stock_jeu_neuf', $stock_jeu_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_console_neuf', $stock_console_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_manga_neuf', $stock_manga_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_figurine_neuf', $stock_figurine_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_dvd_neuf', $stock_dvd_neuf, PDO::PARAM_INT);
    	$query->bindValue(':nomimage', $nomimage, PDO::PARAM_STR);
        $query->execute()or die(print_r($query->errorInfo()));
    		 $query->CloseCursor();

    code sql

    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
    Structure de la table `magasin`
    --
     
    CREATE TABLE IF NOT EXISTS `magasin` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `console_neuf` varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      `figurine_neuf` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      `manga_neuf` varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      `jeu_neuf` varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      `prix_console_neuf` int(11) NOT NULL,
      `prix_jeu_neuf` int(11) NOT NULL,
      `prix_figurine_neuf` int(11) NOT NULL,
      `prix_manga_neuf` int(11) NOT NULL,
      `stock_jeu_neuf` int(11) NOT NULL,
      `stock_console_neuf` int(11) NOT NULL,
      `stock_manga_neuf` int(11) NOT NULL,
      `stock_figurine_neuf` int(11) NOT NULL,
      `dvd_neuf` varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      `prix_dvd_neuf` int(11) NOT NULL,
      `stock_dvd_neuf` int(11) NOT NULL,
      `image` varchar(200) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=98 ;
     
    --
    -- Contenu de la table `magasin`
    --
     
    INSERT INTO `magasin` (`id`, `console_neuf`, `figurine_neuf`, `manga_neuf`, `jeu_neuf`, `prix_console_neuf`, `prix_jeu_neuf`, `prix_figurine_neuf`, `prix_manga_neuf`, `stock_jeu_neuf`, `stock_console_neuf`, `stock_manga_neuf`, `stock_figurine_neuf`, `dvd_neuf`, `prix_dvd_neuf`, `stock_dvd_neuf`, `image`) VALUES
    (95, '../presentation_console_neuve/ps3.php', '', '', '', 350, 0, 0, 0, 0, 5, 0, 0, '', 0, 0, '1302209888.jpg'),
    (93, '', '', '../presentation/eyeshield_21.php', '', 350, 0, 0, 0, 0, 5, 0, 0, '', 0, 0, '1302209617.jpg'),
    (94, '', '', '', '../neuf/final_fantasy_13.php', 350, 0, 0, 0, 0, 5, 0, 0, '', 0, 0, '1302209734.jpg'),
    (92, '', '', '../presentation/dragon_ball.php', '', 350, 0, 0, 0, 0, 5, 0, 0, '', 0, 0, '1302209538.jpg'),
    (91, '', '', '', '../neuf/mafia2.php', 350, 0, 0, 0, 0, 5, 0, 0, '', 0, 0, '1302209409.jpg');
    dans la bdd il y a le prix de 350 sur tout champs prix au lieu d'avoir le prix de chaque article ,

    merci de votre aide,car je ne comprend pas

  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
    ligne 34 tu as juste il manque la suite de la condition

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    de toute manière sa change rien,le problèmes persiste,je comprend pas se qui se passe

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut update qui ne fonctionne pas
    bonjour,

    je reviens vers vous car l'update ne fonctionne pas,quand je débugge mon script pour mes POST ou DATA je vois bien que sa passe bien mais l'update ne se fais pas et passe a l'insertion


    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
      $query=$db->prepare('SELECT jeu_neuf,console_neuf,manga_neuf,figurine_neuf,dvd_neuf,
                                   	prix_jeu_neuf,prix_console_neuf,prix_manga_neuf,prix_figurine_neuf,prix_dvd_neuf,
    			                     stock_jeu_neuf,stock_console_neuf,stock_manga_neuf,stock_figurine_neuf,stock_dvd_neuf
                                                                                                            FROM magasin
    						                                                                                WHERE prix_console_neuf = :prix_console_neuf
    						                                                                                ');
         $query->bindValue(':prix_console_neuf',$prix_console_neuf, PDO::PARAM_STR);
         $query->execute() or die(print_r($query->errorInfo()));
         $data=$query->fetch();
     
       print_r($data);
       print("\n");;
     
     
     
     
     
    	 if  ( 
    	    $data['prix_jeu_neuf']!=$_POST['prix_jeu_neuf'] 
            AND $data['prix_console_neuf']!= $_POST['prix_console_neuf'] 
            AND $data['prix_manga_neuf']!= $_POST['prix_manga_neuf']
            AND $data['prix_figurine_neuf']!= $_POST['prix_figurine_neuf']
    		AND $data['prix_dvd_neuf']!= $_POST['prix_dvd_neuf']
            AND $data['stock_jeu_neuf']!= $_POST['stock_jeu_neuf'] 
            AND $data['stock_console_neuf']!= $_POST['stock_console_neuf']
            AND $data['stock_manga_neuf']!= $_POST['stock_manga_neuf'] 
            AND $data['stock_figurine_neuf']!= $_POST['stock_figurine_neuf']
    		AND $data['stock_dvd_neuf']!= $_POST['stock_dvd_neuf'])
    		{
     
     
     
     
     
     
     
     
    $query = $db->prepare('UPDATE magasin
     
    							              SET
                                                 jeu_neuf = :jeu_neuf,
    							                  console_neuf = :console_neuf,
    							                  manga_neuf = :manga_neuf,
    										      figurine_neuf =:figurine_neuf,
    											  dvd_neuf = :dvd_neuf,										  
     
    										      prix_jeu_neuf = :prix_jeu_neuf,
    							                  prix_console_neuf = :prix_console_neuf,
    							                  prix_manga_neuf = :prix_manga_neuf,
    										      prix_figurine_neuf =:prix_figurine_neuf,
    											  prix_dvd_neuf = :prix_dvd_neuf,
     
    									          stock_jeu_neuf = :stock_jeu_neuf,
    							                  stock_console_neuf = :stock_console_neuf,
    							                  stock_manga_neuf = :stock_manga_neuf,
    							                  stock_figurine_neuf = :stock_figurine_neuf,
    											  stock_dvd_neuf = :stock_dvd_neuf
     
    									          WHERE console_neuf = :console_neuf
    							            ');
     
     
     
    	$query->bindvalue(':console_neuf', $console_neuf, pdo::PARAM_STR);
     
    	$query->bindvalue(':jeu_neuf', $jeu_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':console_neuf', $console_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':manga_neuf', $manga_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':figurine_neuf', $figurine_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':dvd_neuf', $dvd_neuf, pdo::PARAM_STR);
     
    	$query->bindvalue(':prix_jeu_neuf', $prix_jeu_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':prix_console_neuf', $prix_console_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':prix_manga_neuf', $prix_manga_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':prix_figurine_neuf', $prix_figurine_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':prix_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_STR);
     
    	$query->bindvalue(':stock_jeu_neuf', $stock_jeu_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':stock_console_neuf', $stock_console_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':stock_manga_neuf', $stock_manga_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':stock_figurine_neuf', $stock_figurine_neuf, pdo::PARAM_STR);
    	$query->bindvalue(':stock_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_STR);
     
    	$query->execute() or die(print_r($db->errorinfo())); 
     
     
     
     
     
     
    }else{
     
     
     $query=$db->prepare('INSERT INTO magasin   
    		                                          (jeu_neuf,console_neuf,manga_neuf,figurine_neuf,dvd_neuf,image,
    												  prix_jeu_neuf,prix_console_neuf,prix_manga_neuf,prix_figurine_neuf,prix_dvd_neuf,
    												  stock_jeu_neuf,stock_console_neuf,stock_manga_neuf,stock_figurine_neuf,stock_dvd_neuf)
     
                                               VALUES (:jeu_neuf,:console_neuf,:manga_neuf,:figurine_neuf,:dvd_neuf,:nomimage,
    												   :prix_jeu_neuf,:prix_console_neuf,:prix_manga_neuf,:prix_figurine_neuf,:prix_dvd_neuf,
    												   :stock_jeu_neuf,:stock_console_neuf,:stock_manga_neuf,:stock_figurine_neuf,:stock_dvd_neuf
    												   )');
     
    	$query->bindValue(':jeu_neuf', $jeu_neuf, PDO::PARAM_STR);
    	$query->bindValue(':console_neuf', $console_neuf, PDO::PARAM_STR);
    	$query->bindValue(':manga_neuf', $manga_neuf, PDO::PARAM_STR);
    	$query->bindValue(':figurine_neuf', $figurine_neuf, PDO::PARAM_STR);
    	$query->bindValue(':dvd_neuf', $dvd_neuf, PDO::PARAM_STR);
     
    	$query->bindValue(':prix_jeu_neuf', $prix_jeu_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_console_neuf', $prix_console_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_manga_neuf', $prix_manga_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_figurine_neuf', $prix_figurine_neuf, PDO::PARAM_INT);
    	$query->bindValue(':prix_dvd_neuf', $prix_dvd_neuf, PDO::PARAM_INT);
     
    	$query->bindValue(':stock_jeu_neuf', $stock_jeu_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_console_neuf', $stock_console_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_manga_neuf', $stock_manga_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_figurine_neuf', $stock_figurine_neuf, PDO::PARAM_INT);
    	$query->bindValue(':stock_dvd_neuf', $stock_dvd_neuf, PDO::PARAM_INT);
    	$query->bindValue(':nomimage', $nomimage, PDO::PARAM_STR);
        $query->execute()or die(print_r($query->errorInfo()));
    		 $query->CloseCursor();
     
     
     
    	}
    je ne met pas tout le code car trop long,petite précision,au bout d'un moment ou il y a beaucoup de donnée en bdd,elle s' update tout seul sur tout les champs

  5. #5
    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
    Pourquoi tu fais un UPDATE de la table MAGASIN avec le critère WHERE sur le le champ "console_neuf" ?

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    dans un cours que j'ai lu,il faut un where pour l'update non,sinon je vois pas et pour le champs,je voulais mettre id mais il est pas defini.

    euh,la je comprend pas pourquoi se nouveau post fait dans l'ancien,j'ai pourtant cliquer sur nouveau post

  7. #7
    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
    Pourquoi l'id n'est pas défini ?

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    je n'utilise pas l'id dans mon formulaire donc si je veux utiliser l'id dans le where,je vois pas comment je pourrais faire,car j'ai déjà utilisé pas mal de champs de ma bdd est sa fonctionne pas mais par contre sa fonctionne sur wamp sauf pour jeu_neuf ou la il me renvoie rien

  9. #9
    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
    L'id doit etre transmis dans le formulaire en champ hidden par exemple.

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    je viens de pensais a une chose,si on connais pas l'id on peut pas l'envoyer par le formulaire

  11. #11
    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 cherches a mettre à jour une ligne qui existe déjà, donc qui a un id, donc tu connais cet id.

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    j'ai rajouté
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     <input type="hidden" name="code" value="'.$id.'" />
    dans mon formulaire mais sa donne rien,je vois pas comment faire pour que l'id passe vers mon traitement,je sais que je dois utiliser $_POST pour verifier qu'il est bien la mais sa me met une erreur de indefini index

  13. #13
    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 la variable $id correspond a quelque chose dans ton code ?
    Est-ce quand tu regardes la source HTML de ton formulaire tu vois la valeur bien remplie ?

  14. #14
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    quand je regarde la source,je vois value =12,sa correspond pas a l'id de ma base de donnée,je voulais faire une requete pour récupéré l'id mais je vois pas comment la mettre dans l'hidden

  15. #15
    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
    Si tu vois bien value="12" dans ton champ hidden, c'est que c'est bon.
    Tu attendais quoi d'autre ?

  16. #16
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut
    bin je pensais a voir l'id de la ligne qui correspond au champs demandé par exemple l'id du jeu inséré

  17. #17
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    295
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 295
    Points : 71
    Points
    71
    Par défaut changer l'id selon le champ
    Bonjour,
    je cherche a mettre via un formulaire différent article en base avec son stock et son prix et faire un update en cas ou le prix ou le stock change

    Le problème est que je voudrais utiliser la session pour l'update.J'ai déjà essayé lastinsertid mais sa ne marche pas, car l'id est pas repris en rapport a la ligne inséré,en se moment mon code ne fait que des updates et plus des insert car l'id est toujours le mémés.Je ne vois pas comment je pourrais mettre l'id de l'article inséré en session et la récupéré pour faire l'update

    J’espère que je me suis fait bien comprendre,si vous voulez que je mettes mon formulaire ou d'autre explication que j'aurais oublié, dites le.

    merci d'avance de votre aide

    ps:le prix devrais avoir des décimal mais pas encore réussi a les mettre


    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
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    <?php
    Session_start();
    include('../tests/cookie.php');
    ;?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
       <head>
           <title>Aux milles trésors du dragon</title>
           <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    	   <link rel="stylesheet" media="screen" type="text/css" title= "site" href="../css/site.css" /> 
     
       </head>
     
     <?php 
     
     include("../includes/pseudo.php"); 
     include("../includes/functions.php");
     include("../includes/constants.php");
     include("../includes/identifiants.php");
     
     
     
     
     
     
     
     
     
     
    	$jeu_neuf = htmlspecialchars(addslashes($_POST['jeu_neuf']));
        $manga_neuf = htmlspecialchars(addslashes($_POST['manga_neuf']));
    	$figurine_neuf = htmlspecialchars(addslashes($_POST['figurine_neuf']));
    	$console_neuf = htmlspecialchars(addslashes($_POST['console_neuf']));
    	$dvd_neuf = htmlspecialchars(addslashes($_POST['dvd_neuf']));
     
        $prix_jeu_neuf = htmlspecialchars(addslashes($_POST['prix_jeu_neuf']));
        $prix_manga_neuf = htmlspecialchars(addslashes($_POST['prix_manga_neuf']));
    	$prix_figurine_neuf = htmlspecialchars(addslashes($_POST['prix_figurine_neuf']));
    	$prix_console_neuf = htmlspecialchars(addslashes($_POST['prix_console_neuf']));
    	$prix_dvd_neuf = htmlspecialchars(addslashes($_POST['prix_dvd_neuf']));
     
        $stock_jeu_neuf = htmlspecialchars(addslashes($_POST['stock_jeu_neuf']));
        $stock_manga_neuf = htmlspecialchars(addslashes($_POST['stock_manga_neuf']));
    	$stock_figurine_neuf = htmlspecialchars(addslashes($_POST['stock_figurine_neuf']));
    	$stock_console_neuf = htmlspecialchars(addslashes($_POST['stock_console_neuf']));
        $stock_dvd_neuf = htmlspecialchars(addslashes($_POST['stock_dvd_neuf']));
     
     
     
     
     
     
    		if (!empty($_FILES['image']['size']))
     
    	{
            //On définit les variables :
            $maxsize = 35000; //Poid de l'image
            $maxwidth = 300; //Largeur de l'image
            $maxheight = 300; //Longueur de l'image
            $extensions_valides = array( 'jpg' , 'jpeg' , 'gif' , 'png', 'bmp' ); //Liste des extensions valides
     
            if ($_FILES['image']['error'] > 0)
            {
                    $avatar_erreur = "Erreur lors du tranfsert de l'avatar : ";
            }
            if ($_FILES['image']['size'] > $maxsize)
            {
                    $i++;
                    $image_erreur1 = "Le fichier est trop gros : (<strong>".$_FILES['image']['size']." Octets</strong>    contre <strong>".$maxsize." Octets</strong>)";
            }
     
                $image_sizes = getimagesize($_FILES['image']['tmp_name']);
            if ($image_sizes[0] > $maxwidth OR $image_sizes[1] > $maxheight)
            {
                    $i++;
                    $image_erreur2 = "Image trop large ou trop longue : 
                    (<strong>".$image_sizes[0]."x".$image_sizes[1]."</strong> contre <strong>".$maxwidth."x".$maxheight."</strong>)";
            }
     
            $extension_upload = strtolower(substr(  strrchr($_FILES['image']['name'], '.')  ,1));
            if (!in_array($extension_upload,$extensions_valides) )
            {
                    $i++;
                    $image_erreur3 = "Extension de l'avatar incorrecte";
            }
        }
     
     
     
     
             $nomimage=(!empty($_FILES['image']['size']))?move_image($_FILES['image']):''; 
     
     
     
     
    		$query = $db->prepare("SELECT COUNT(*) AS nombre_entree FROM `magasin` WHERE id = :id");
    		$query->bindValue(':id', $_SESSION['id'], PDO::PARAM_INT);
    		$query->execute();
    		$donnees = $query->fetch();
    		$nombre_lignes = $donnees['nombre_entree'];
     
     
     if ($nombre_lignes > 0)  {
     
     
                 $query = $db->prepare('UPDATE magasin
    	
    							                     SET  jeu_neuf = :jeu_neuf,
    													  console_neuf = :console_neuf,
    													  manga_neuf = :manga_neuf,
    													  figurine_neuf =:figurine_neuf,
    													  dvd_neuf = :dvd_neuf,
                                                
    													  prix_jeu_neuf = :prix_jeu_neuf,
    													  prix_console_neuf = :prix_console_neuf,
    													  prix_manga_neuf = :prix_manga_neuf,
    													  prix_figurine_neuf =:prix_figurine_neuf,
    													  prix_dvd_neuf = :prix_dvd_neuf,
    													  
    													  stock_jeu_neuf = :stock_jeu_neuf,
    													  stock_console_neuf = :stock_console_neuf,
    													  stock_manga_neuf = :stock_manga_neuf,
    													  stock_figurine_neuf = :stock_figurine_neuf,
    													  stock_dvd_neuf = :stock_dvd_neuf
    											  
    									          WHERE id = :id
    							            ');
     
     
     
     
    			$query->bindvalue(':id',$_SESSION['id'], pdo::PARAM_INT);
    			$query->bindvalue(':jeu_neuf', $jeu_neuf, pdo::PARAM_STR);
    			$query->bindvalue(':console_neuf', $console_neuf, pdo::PARAM_STR);
    			$query->bindvalue(':manga_neuf', $manga_neuf, pdo::PARAM_STR);
    			$query->bindvalue(':figurine_neuf', $figurine_neuf, pdo::PARAM_STR);
    			$query->bindvalue(':dvd_neuf', $dvd_neuf, pdo::PARAM_STR);
     
    			$query->bindvalue(':prix_jeu_neuf', $prix_jeu_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':prix_console_neuf', $prix_console_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':prix_manga_neuf', $prix_manga_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':prix_figurine_neuf', $prix_figurine_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':prix_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_INT);
     
    			$query->bindvalue(':stock_jeu_neuf', $stock_jeu_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':stock_console_neuf', $stock_console_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':stock_manga_neuf', $stock_manga_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':stock_figurine_neuf', $stock_figurine_neuf, pdo::PARAM_INT);
    			$query->bindvalue(':stock_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_INT);
     
    			$query->execute() or die(print_r($db->errorinfo())); 
    		    $query->CloseCursor();
     
     
     
     
    }else{
     
     
     
     
     
    			$query = $db->prepare('INSERT INTO magasin    (jeu_neuf,console_neuf,manga_neuf,image,
    														  figurine_neuf,dvd_neuf,prix_jeu_neuf,
    														  prix_console_neuf, prix_manga_neuf,prix_figurine_neuf,
    														  prix_dvd_neuf,stock_jeu_neuf,stock_console_neuf,
    														  stock_manga_neuf,stock_figurine_neuf,stock_dvd_neuf)
    														  
    											   VALUES     (:jeu_neuf,:console_neuf,:manga_neuf,:nomimage,:figurine_neuf,:dvd_neuf,			  
    														  :prix_jeu_neuf,:prix_console_neuf,:prix_manga_neuf,:prix_figurine_neuf, 
    														  :prix_dvd_neuf,:stock_jeu_neuf,:stock_console_neuf,
    														  :stock_manga_neuf,:stock_figurine_neuf,:stock_dvd_neuf)
    													       ');
     
     
     
     
     
    				$query->bindvalue(':jeu_neuf', $jeu_neuf, pdo::PARAM_STR);
    				$query->bindvalue(':console_neuf', $console_neuf, pdo::PARAM_STR);
    				$query->bindvalue(':manga_neuf', $manga_neuf, pdo::PARAM_STR);
    				$query->bindvalue(':figurine_neuf', $figurine_neuf, pdo::PARAM_STR);
    				$query->bindvalue(':dvd_neuf', $dvd_neuf, pdo::PARAM_STR);
     
    				$query->bindvalue(':prix_jeu_neuf', $prix_jeu_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':prix_console_neuf', $prix_console_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':prix_manga_neuf', $prix_manga_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':prix_figurine_neuf', $prix_figurine_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':prix_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_INT);
     
    				$query->bindvalue(':stock_jeu_neuf', $stock_jeu_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':stock_console_neuf', $stock_console_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':stock_manga_neuf', $stock_manga_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':stock_figurine_neuf', $stock_figurine_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':stock_dvd_neuf', $prix_dvd_neuf, pdo::PARAM_INT);
    				$query->bindvalue(':nomimage', $nomimage, pdo::PARAM_STR);
    				$query->execute() or die(print_r($db->errorinfo())); 
     
    				 $_SESSION['id'] = $id;
    				 $_SESSION['jeu_neuf'] = $jeu_neuf;
    				 $_SESSION['console_neuf'] = $console_neuf;
    				 $_SESSION['manga_neuf'] = $manga_neuf;
    				 $_SESSION['figurine_neuf'] = $figurine_neuf;
    				 $_SESSION['dvd_neuf'] = $dvd_neuf;
    		         $query->CloseCursor(); 
     
     
     
     
     
     
     
     
        echo'<h1>donnée rentré</h1>';
    	echo'<p>donnée bien rentré</p>
    	<p>cliquez <a href = "../tests/magasin.php">ici</a> </p>';
     
     
     
     
     
     
     
     
     
     
     
    ?>
     
     
     
                   </div>
              </body>
    </html>

  18. #18
    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 mis
    mais $id n'est pas défini dans ton code.

    Développe en affichant toutes les erreurs, ca te remontera ce genre de problèmes.

    Et présente mieux ton code, il est illisible.

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

Discussions similaires

  1. [Toutes versions] Code VBA qui fonctionne mal
    Par Eddy95500 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 07/07/2015, 18h10
  2. [XL-2007] code qui fonctionne mal
    Par grisan29 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 27/06/2012, 18h02
  3. Touches "n" et "h" qui fonctionnent mal
    Par J0r_x dans le forum Sécurité
    Réponses: 1
    Dernier message: 17/11/2007, 17h29
  4. Démo qui fonctionne mal sur Mac OS
    Par shams dans le forum Ogre
    Réponses: 12
    Dernier message: 22/05/2007, 18h34
  5. un DELETE qui fonctionne mal
    Par HULK dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 06/02/2006, 18h59

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