Précédent   Forum des professionnels en informatique > PHP > Langage
Langage Forum sur le langage PHP, la POO, les conventions, la sécurité, etc. Avant de poster : FAQ Langage, toutes les FAQ PHP, cours langage et sources PHP
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/05/2011, 17h08   #1
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
Par défaut fonction modifier en php5

bonjour,
j'ai une problème à la modification des données des bases des données mysql,
j'essaye avec le code suivant:
Code :
1
2
3
4
5
6
7
8
9
10
public function modifier()
{
 if(isset($_POST['sauvegarder'])){
 
$requete="UPDATE circuit SET ( id_circuit =$_POST['id_circuit'], Nomcircuit =$_POST['Nomcircuit'], Villededépart =$_POST['Villededépart'],
 Jourdedépart =$_POST['Jourdedépart'], Jourderetour =$_POST['Jourderetour'], Duree =$_POST['Duree'], Prix =$_POST['Prix'], Supplementsingle=$_POST['Supplementsingle'], Reductionenfant =$_POST['Reductionenfant'] , Description =$_POST['Description']) where id_circuit =$_POST['id_circuit'];";
$result =mysql_query($requete);
 
}
}
mais il m'affiche la faute suivante:

Citation:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\EasyPHP-5.3.3\www\pfe\recherchedecircuit.php on line 328
merci d'avance.
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/05/2011, 17h14   #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
tu as deux choix :
Code :
$requete="UPDATE circuit SET ( id_circuit =" . $_POST['id_circuit'] .".....
Code :
$requete="UPDATE circuit SET ( id_circuit = $_POST[id_circuit] .....
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/05/2011, 19h36   #3
Membre actif
 
Avatar de Causa Sui
 
Inscription : mai 2003
Messages : 133
Détails du profil
Informations forums :
Inscription : mai 2003
Messages : 133
Points : 172
Points : 172
Plus la solution magique à laquelle on ne pense jamais: entourer la variable de {}
Code PHP :
$requete="UPDATE circuit SET ( id_circuit = {$_POST['id_circuit']} .....
… ce qui permet d'inclure des variables littérales au nom compliqué dans une chaîne
Causa Sui est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 13/05/2011, 11h59   #4
Membre chevronné
 
Avatar de Elwyn
 
Homme
Ingénieur systèmes et réseaux
Inscription : juillet 2006
Messages : 836
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Ingénieur systèmes et réseaux

Informations forums :
Inscription : juillet 2006
Messages : 836
Points : 712
Points : 712
Pensez tout de même à protéger un minimum ces variables
__________________
Dire Straits, Bob Dylan, Led Zeppelin, the Who, Pink Floyd, AC/DC, Guns & Roses, the Doors, ...
Elwyn est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 11h48   #5
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
merci la faute précedente est ignorée mais il ne fais aucune modification à la base des données.
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 11h51   #6
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 823
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 823
Points : 3 449
Points : 3 449
Je comprends qu'il n'y a plus de msg d'erreur et que la base de données n'est pas mise à jour.

Montre-nous le bout de code incriminé.
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 11h55   #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
Il manque toutes les bases du traitement des requêtes :

Code :
1
2
3
4
5
$requete="UPDATE circuit SET ( 
   id_circuit = "  . intval($_POST['id_circuit']) . ", 
   Nomcircuit ='" . mysql_real_escape_string($_POST['Nomcircuit']) . "',
   Villededépart ='"  . mysql_real_escape_string($_POST['Villededépart']) . "',
   .......
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 11h57   #8
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
je essaye de modifier un peu mon fonction mais il ne fonctionne pas voici mon code:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
public function modifier($id_circuit,$Nomcircuit,$Villededépart,$Jourdedépart,$Jourderetour,$Durée,$Prix,$Supplementsingle,$Reductionenfant,$Description)
{
if(isset($_POST['id_circuit']) || isset($_POST['Nomcircuit']) || isset($_POST['Villededépart']))
 $id_circuit=$_POST['id_circuit'];
 $Nomcircuit=$_POST['Nomcircuit'];
 $Villededépart=$_POST['Villededépart'];
 if (!empty($id_circuit) && !empty($Nomcircuit) && !empty($Villededépart))
 {
 
$req="UPDATE circuit SET  id_circuit ='$id_circuit', Nomcircuit = '$Nomcircuit', Villededépart = '$Villededépart', Jourdedépart = '".$Jourdedépart."' , Jourderetour = '".$Jourderetour."', Durée = '".$Durée."', Prix = '".$Prix."', Supplementsingle= '".$Supplementsingle."', Reductionenfant = '".$Reductionenfant."' Description = '".$Description."' where id_circuit LIKE '%".$id_circuit."%';";
$result= @mysql_query($req);
}
}
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 12h01   #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
Je ne pense pas que l'id_circuit soit une chaine approximative :
Code :
where id_circuit  = $id_circuit
Il manque de plus toujours tous les echappement des variables avec mysql_real_escape_string().
Il y a toujours des variables avec des accents, ce qu'on t'a déjà deconseillé.
Il y a toujours le @ qu'on t'a déjà indiqué d'enlevé.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 12h17   #10
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
j'essaye encore une fois avec le code proposée mais il m'affiche la faute undefined index pour tous les attributs malgré que j'ai mon formulaire à une autre page html
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 12h23   #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
Déjà soit tu passes les arguments en paramètres de la fonction, soit tu utilises directement $_POST dans ta fonction mais pas les deux.

Ensuite pour debuguer affiche ce que contient $_POST.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 13h25   #12
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
d'abord,on cherche un circuit en faire entrer un id_circuit qui m'affiche dans un formulaire tous les informations sur cette circuit et dans la meme formulaire on va modifier les informations.
j'essaye avec ce code de formulaire ou je fais le recherche qui fonctionne:
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
 
public function cherchercircuit($id_circuit)
 
	{  
     if(isset($_POST['chercher']))
             {
			$requete ="select * from circuit where id_circuit LIKE '%".$_POST['id_circuit']."%';";
			if($result =mysql_query($requete))
			{ 
			$row=mysql_fetch_row($result);
 
 
			echo "<table width='100%' height='500'>
					<center>
						<tr>
						<td>
						<font color='white'>id_circuit:</font>
						</td>
						<td>
						<input name='id_circuit' type='text' value=$row[0] >
						</td>
						</tr>
						<tr>
						<td>
						<font color='white'>Nom circuit</font>
						</td>
						<td>
						<input name='Nomcircuit' type='text' value= $row[1] >
						</td>
						</tr>
						 <tr>
						  <td>
						    <font color='white'>Ville de départ:</font>
						  </td>
						  <td>
						    <input name='Villededépart' type='text'  value=$row[2]>
						  </td>
						 </tr>
						 <tr>
							<td>
								<font color='white'>Jour de départ:</font>
						    </td>
						    <td>
								 <input name='Jourdedépart' type='text' value=$row[3] >
						    </td>
						 </tr>
 
						 <tr>
							 <td>
								 <font color='white'>Jour de retour:</font>
						     </td>
						     <td>
								 <input name='Jourderetour' type='text' value=$row[4] >
						     </td>
						 </tr>
						 <tr>
						     <td>
						         <font color='white'>Durée:</font>
						     </td>
						     <td>
						         <input name='Durée' type='text' value=$row[5] >
						     </td>
						 </tr>
						 <tr>
						     <td>
						         <font color='white'>Prix:</font>
						     </td>
						     <td>
						         <input name='Prix' type='text' value=$row[6] >
						     </td>
						 </tr>
						 <tr>
						     <td>
								 <font color=white>Description:</font>
							 </td>
						     <td>
 
							 <textarea rows=10 cols=17 name='Description' value=$row[7] ></textarea> 
 
						     </td>
						 </tr>
 
						 <tr>
					         <td>
						     </td>
						     <td>
						     </td>
						 <tr>
						     <td>
							     <a href='ajouter.html'><img src='précédent1.jpg' width='80'height='80'></a>
						     </td>
						     <td>
						  <center>
						  <a href='admini.html'><img src='accueil.jpg' width='80' height='80'></a>
						  </center>
						  </td>
 
					    <td>
						 <form method='POST' action='modifiercircuit.php'>
						<button name='sauvegarder' value='sauvegarder' type='submit' ><img src='sauvegarde.jpg' width='100' height='100'></button>
						 </form>
						</td>
					</tr>
					</center>
			</table>";
			}}}
puis on fait l'appel de ce methode dans la page cherchercircuit.php
Code :
1
2
3
4
5
6
7
 
<?php 
					 include("recherchedecircuit.php");
					 $obj=new circuit('.$id_circuit.','.$Nomcircuit.','.$Villededépart.','.$Jourdedépart.','.$Jourderetour.','.$Durée.','.$Prix.','.$Supplementsingle.','.$Reductionenfant.','.$Description.');
					 $obj->cherchercircuit('.$id_circuit.');
 
					 ?>
ce code fonctionne mais la problème est dans la modification qui a le code suivant:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
public function modifier()
{
if(isset($_POST['sauvegarder'])){
 {
 
$requete="UPDATE circuit SET ( 
   id_circuit = "  . intval($_POST['id_circuit']) . ", 
   Nomcircuit ='" . mysql_real_escape_string($_POST['Nomcircuit']) . "',
   Villededépart ='"  . mysql_real_escape_string($_POST['Villededépart']) . "',
   Jourdedépart ='"  . mysql_real_escape_string($_POST['Jourdedépart']) . "',
   Jourderetour ='"  . mysql_real_escape_string($_POST['Jourderetour']) . "',
   Durée ='"  . mysql_real_escape_string($_POST['Durée']) . "',
   Prix ='"  . mysql_real_escape_string($_POST['Prix']) . "',
   Description ='"  . mysql_real_escape_string($_POST['description']) . "')";
}
}
}
et on fait l'appel de cette fonction dans un autre page modifiercircuit.php:
Code :
1
2
3
4
5
6
 
<?php
				include('recherchedecircuit.php');
				$obj= new circuit;
				$obj->modifier();
				?>
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 14h11   #13
Membre expérimenté
 
Avatar de FMaz
 
Inscription : mars 2005
Messages : 648
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 648
Points : 527
Points : 527
Un UPDATE sans WHERE ?
Tu modifie tous les circuits pour les rendres identiques ?
Si id_circuit n'est pas une clé primaire, ca risque effectivement d'être problématique.
FMaz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 14h23   #14
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
je fais un where mais ça ne résoulut pas la problème undefined index
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 14h26   #15
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 823
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 823
Points : 3 449
Points : 3 449
Message d'erreur ?
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 14h34   #16
Membre expérimenté
 
Avatar de FMaz
 
Inscription : mars 2005
Messages : 648
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 648
Points : 527
Points : 527
Quel index est undefined ?
FMaz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 14h59   #17
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
tous les index sont undefined
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 15h04   #18
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 823
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 823
Points : 3 449
Points : 3 449
Citation:
Envoyé par rachouda Voir le message
tous les index sont undefined
Donc le formulaire n'envoie pas les champs attendus.
Ou alors $_POST est altéré entre temps.
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 15h11   #19
 
Femme rachida ben khlifa
Étudiant
Inscription : avril 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Femme rachida ben khlifa
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 30
Points : -4
Points : -4
alors qu'est ce que je doit faire maintenant?
rachouda est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/05/2011, 15h20   #20
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 823
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 823
Points : 3 449
Points : 3 449
Vérifier dans modifiercircuit.php si tu reçois bien le formulaire en POST.
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h46.


 
 
 
 
Partenaires

Hébergement Web