Bonjour à tous,
J essaye de faire un tableau qui extrait les données d'une table Users et dans lequel je peux modifier les valeurs.
J'ai 2 problèmes :
- Pour ce qui est du Champ NomComplet, c'est un champ composé du nom et du prénom.
Dans le tableau, il m'affiche uniquement le Nom et oublie l'espace et le prénom.
- L'autre problème, quand je cliques sur le bouton modifier après avoir modifier un champs, j'ai une erreur : ClientErreur : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '13'' at line 3
L'ID 13 est bien l'id du User que je veux modifier.
J'ai fait un echo des valeurs pour vérifier, tout est ok sauf le champs NomComplet.
Voici le code: Merci beaucoup !
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 <?php include('_connexion.php'); ?> <?php $select = "SELECT * FROM Users ORDER BY Nom ASC"; $result = mysql_query($select) or die ('Erreur : '.mysql_error() ); $total = mysql_num_rows($result); if($total) { // debut du tableau echo '<div align="center">'; echo '<table bgcolor="#FFFFFF">'."\n"; echo '<tr>'; echo 'LISTE DES UTILISATEURS AU '; setlocale (LC_ALL, 'fr_FR'); echo (strftime("%A %d %B")); echo '<br>'; echo '<br>'; echo '<td bgcolor="#005AA9"><b><u>id</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Nom</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Prenom</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Nom Complet</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Login</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Password</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Mail</u></b></td>'; echo '<td bgcolor="#005AA9"><b><u>Groupe</u></b></td>'; echo '</tr>'."\n"; $i = 0; while($row = mysql_fetch_array($result, MYSQL_BOTH)) { $color = ++$i % 2 ? '#CCCCCC' : '#FFFFFF'; echo '<tr>'; echo '<form action="" method="POST">'; echo '<td> <input readonly method="POST" style="border-style: none; border:0; background-color:'.$color.'" name="id" value='.$row['id'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; background-color:'.$color.'" name="Nom" value='.$row['Nom'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; background-color:'.$color.'" name="Prenom" value='.$row['Prenom'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; background-color:'.$color.'" name="NomComplet" value='.$row["NomComplet"].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; background-color:'.$color.'" name="Login" value='.$row['Login'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; margin:auto; background-color:'.$color.'" name="Password" value='.$row['Password'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; margin:auto; background-color:'.$color.'" name="Mail" value='.$row['Mail'].'></td>'; echo '<td> <input method="POST" style="border-style: none; border:0; margin:auto; background-color:'.$color.'" name="Groupe" value='.$row['Groupe'].'></td>'; echo '<td><input type="submit" name="Modifier" value="Modifier"/> </form>'; echo '<td><input type="submit" name="Supprimer" value="Supprimer"/> </form>'; echo '</tr>'."\n"; // size="" } echo '</table>'."\n"; echo '</div>'; // fin du tableau. if(isset($_POST['Modifier'])) // si un clic a été fait sur le bouton submit (Modifier) { $id=$_POST['id']; $Nom=$_POST['Nom']; $Prenom=$_POST['Prenom']; $NomComplet=$_POST['NomComplet']; $Login=$_POST['Login']; $Password=$_POST['Password']; $Mail=$_POST['Mail']; $Groupe=$_POST['Groupe']; echo $id; echo $Nom; echo $Prenom; echo $NomComplet; echo $Login; echo $Password; echo $Mail; echo $Groupe; $reqModif = "UPDATE Users SET Nom = '$Nom', Prenom = '$Prenom', Login = '$Login', Password = '$Password', Mail = '$Mail', Groupe = '$Groupe', WHERE id = '$id'"; $res = mysql_query($reqModif) or die ('Erreur : '.mysql_error() ); $tot = mysql_free_result($res); } } mysql_close(); // on ferme la connexion ?>
Partager