j'essaye de mettre à jour des lignes dans ma table postgresql avec php, mais j'arrive pas à voir mes lignes modifiées, et meme l'erreur n'est pas affichée
voici mon code:
ma table a comme structure:
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 <form autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1"> <label for="identif">Identifiant </label> <input name="identif" id="identif" type="text"/> <button name="chercher" id="chercher" type="submit"> Lancer recherche</button> </form> <form name="form2" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <? if ((isset($_POST['identif'])) && (!empty($_POST['identif'])) && (isset($_POST['chercher']))) { $conn = pg_pconnect("dbname=postgres host=localhost port=5432 user=postgres password=postgres"); if ($conn) { //print "Successfully connected to database: " . pg_dbname($conn) . // " on " . pg_host($conn) . "</br>\n"; $id = pg_escape_string($_POST['identif']); $result = pg_query($conn, "SELECT * from chercheur WHERE idfcher='" . $id . "';"); } else { print pg_last_error($conn); exit; } if (!$result) { $errormessage = pg_last_error(); echo "Error with query: " . $errormessage; exit(); } else { while ($myrow = pg_fetch_row($result)) { echo '<hr><h2>Informations du chercheur trouvé:</h2>'; echo '<table> <tr> <td><label for="nom">Nom du chercheur</label></td> <td><input value="' . $myrow[0] . '" name="nom" id="nom" type="text" /></td> </tr> <td> <label for="prenom">Prenom du chercheur</label></td> <td> <input value="' . $myrow[2] . '" name="prenom" id="prenom" type="text" /></td> </tr> <tr> <td><label for="user">Identifiant </label></td> <td><input value="' . $myrow[1] . '" name="user" id="user" type="text" /></td> </tr> <tr> <td><label for="pass">Mot de passe</label></td> <td><input value="' . $myrow[3] . '" name="pass" id="pass" type="password" /></td> </tr> <td><label for="mail">Email du chercheur</label></td> <td><input value="' . $myrow[4] . '" name="mail" id="mail" type="email" /></td> </tr> <td><label for="grade">Grade</label></td> <td> <input value="' . $myrow[5] . '" name="grade" id="grade" type="text" /></td> </tr> <tr> <td><label for="naiss">Date de naissance</label></td> <td><input value="' . $myrow[6] . '" name="naiss" id="naiss" type="date" /></td> </tr> <tr> <td><label for="lieu">Lieu de naissance</label></td> <td><input value="' . $myrow[7] . '" name="lieu" id="lieu" type="text" /></td> </tr> <tr> <td><label for="divis">Division</label></td> <td><input value="' . $myrow[8] . '" name="divis" id="divis" type="text" /></td> </tr><tr><td> </td></tr> <tr> <td></td> <td><button name="submit2" id="submit2" type="submit" >Mettre à jour</button> <button name="annuler" id="annuler" type="reset" >Réinitialiser</button></td> </tr> </table>'; if ((isset($_POST['submit2']))) { $idf = pg_escape_string($_POST['user']); $pass = pg_escape_string($_POST['pass']); $name = pg_escape_string($_POST['nom']); $pre = pg_escape_string($_POST['prenom']); $mail = pg_escape_string($_POST['mail']); $naissance = pg_escape_string($_POST['naiss']); $lieu = pg_escape_string($_POST['lieu']); $division = pg_escape_string($_POST['divis']); $gr = pg_escape_string($_POST['grade']); $result = pg_query($conn, "UPDATE chercheur SET nomcher='" . $name . "' and precher='" . $pre . "' and passcher='" . $pass . "' and mailcher='" . $mail . "' and naisscher=date('" . $naissance . "') and lieucher='" . $lieu . "' and divicher='" . $division . "'and gradcher='" . $gr . "' where idfcher='" . $idf . "';"); if (!$result) { $errormessage = pg_last_error(); echo "Error with query: " . $errormessage; exit(); } else { echo "mise à jour avec succès"; } } } } pg_free_result($result); pg_close(); } ?> </form>
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 CREATE TABLE chercheur ( nomcher text, idfcher text NOT NULL, precher text, passcher text, mailcher text, gradcher text, naisscher date, lieucher text, divicher text, CONSTRAINT "Chercheur_pkey" PRIMARY KEY (idfcher) )
Partager