slt a tous je suis nouveau ici je viens solliciter votre aide pour mon script qui ne marche pas
j'essais de recuperer une ligne depuis ma BD mysql avec PDO il m'affiche
une erreur du typeMerci d'avanceFatal error: Call to a member function fetch() on a non-object in E:\wamp\www\miniProjet\php\maj.php on line 13.
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 <?php //require'sqlconnect.php'; if(!empty($_POST[mesvilles])&& isset($_POST[modif])) { try { $dsn="mysql:host=localhost;dbname=gmairie"; $idcom=new PDO($dsn,"root",""); $cle=$_POST[mesvilles]; echo"$cle"; $req="select numeroville,nomville,superficie from ville where nomville=$cle"; $result=$idcom->query($req,PDO::FETCH_OBJ); $row=$result->fetch(); $num=$row['numeroville']; $nom=$row['nomville']; $sup=$row['superficie']; echo"$sup"; } catch(PDOException $except) { echo "erreur"; } echo "<form action= \"<?php echo $_SERVER[PHP_SELF];?>\" method=\"post\">"; echo "<fieldset>"; echo"<legend><b>MISE A JOUR D'UNE VILLE</b></legend>"; echo "<table>"; echo "<tr>"; echo "<td>Nom Ville : </td>"; echo "<td> <input type=\"text\" name=\"nom\" value=\"$nom\"></td>"; echo "</tr>"; echo "<tr>"; echo "<td>superficie : </td>"; echo "<td> <input type=\"text\" name=\"superficie\" value=\"$sup\"></td>"; echo "</tr>"; echo "<input type=\"reset\" name=\"ann\" value=\"ANNULER\">"; echo "<input type=\"submit\" name=\"enreg\" value=\"ENREGISTRER\">"; echo"</table>"; echo"</fieldset>"; echo"</form>"; if(!empty($_POST[nom])&& isset($_POST[enreg])&&!empty($_POST[superficie])) { $clenom=$_POST[nom]; $clesuperficie=$_POST[superficie]; $req="update ville set nomville=$clenom numeroville=$clenumero superficie=$clesuperficie where numero=$num"; $result=$idcom->exec($req); if($result) { echo("MISE A JOUR EFFECTUEE"); } } } ?>
Partager