Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 07/04/2011, 23h21   #1
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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 :
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 :
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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/04/2011, 23h36   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
ligne 34 tu as juste il manque la suite de la condition
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/04/2011, 11h06   #3
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
de toute manière sa change rien,le problèmes persiste,je comprend pas se qui se passe
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 14h16   #4
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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 :
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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 15h18   #5
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Pourquoi tu fais un UPDATE de la table MAGASIN avec le critère WHERE sur le le champ "console_neuf" ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 15h30   #6
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 16h00   #7
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Pourquoi l'id n'est pas défini ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 16h25   #8
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 17h34   #9
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
L'id doit etre transmis dans le formulaire en champ hidden par exemple.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 19h25   #10
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
je viens de pensais a une chose,si on connais pas l'id on peut pas l'envoyer par le formulaire
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/04/2011, 20h02   #11
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Tu cherches a mettre à jour une ligne qui existe déjà, donc qui a un id, donc tu connais cet id.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/04/2011, 22h39   #12
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
j'ai rajouté
Code :
 <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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/04/2011, 06h28   #13
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
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 ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/04/2011, 20h46   #14
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/04/2011, 20h47   #15
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Si tu vois bien value="12" dans ton champ hidden, c'est que c'est bon.
Tu attendais quoi d'autre ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/04/2011, 21h12   #16
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
bin je pensais a voir l'id de la ligne qui correspond au champs demandé par exemple l'id du jeu inséré
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/05/2011, 16h10   #17
Futur Membre du Club
 
Inscription : janvier 2011
Messages : 146
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 146
Points : 15
Points : 15
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 :
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>
arckaniann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/05/2011, 18h20   #18
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
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.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h22.


 
 
 
 
Partenaires

Hébergement Web