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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Modificatioin-PDO</title>
</head>
<body>
Entrer l'identifiant pour  modifier<br>
			<form method="post" action="modifpdo.php">
			ID <input type="text" name="id">&nbsp;&nbsp;&nbsp;
			<input type="submit" name="valider" value="valider">
			</form>
			<?php
			if(isset($_POST['valider'])){
			$id=$_POST['id'];
			$user    = 'root';
			$pass      = '';
			$dsn = 'mysql:host=localhost;dbname=test';
			try {
				$dbh = new PDO($dsn, $user, $pass);
				} 
				catch (PDOException $e) 
				{
			die("Erreur ! : ". $e->getMessage());
				}
				$id=$_POST['id'];
				$nom="";
				$email="";
			$req="SELECT nom, email FROM gens WHERE id=$id";
			$result=$dbh->query($req);
			$row=$result->fetch(PDO::FETCH_BOTH);
			}
			?>
			        <form method="post" action="modifpdo.php">
			Nom  	<input type="text" value="<?php echo $row['nom'];?>" name="nom">&nbsp;&nbsp;&nbsp;
			Email   <input type="text" value="<?php echo $row['email'];?>" name="email">&nbsp;&nbsp;&nbsp;
					<input type="submit" name="Modifier" value="Modifier">
					</form>
			<?php
				if(isset($_POST['Modifier'])){
				$id="";
				$nom="";
				$email="";
				$user="root";
				$pass="";
				$dsn = 'mysql:host=localhost;dbname=test';
				try {
					$dbh = new PDO($dsn, $user, $pass);
					} 
				catch (PDOException $e) 
					{
				die("Erreur ! : ". $e->getMessage());
					}
								$req=$dbh->prepare("UPDATE gens SET  nom=:$nom, email=:$email WHERE id=:$id");
								//$req->execute(array('nom'=>$nom,'email'=>$email,'id'=>$id));
										 }
			?>
</body>
</html>