Bonjour, quand je clique sur le lien éditer de la page admin / index.php devant chaque ville, j'ai toujours la même ville qui s'affiche dans le formulaire de mise à jour de la ville.

Merci pour votre aide.

class/cityManager.php

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
 
class cityManager {
 
	private $_db;
 
	public function __construct(PDO $db) {
 
		$this->setDb($db);
	}
 
	public function setDb($dbh) {
 
		$this->_db = $dbh;
	}
 
        public function getDisplayCity(City $city) {
 
    	$sql = 'SELECT city_id, city_name, city_text FROM city WHERE city_id = :city_id';
 
    	$city_id = $city->getCityId();
    	$city_name = htmlspecialchars($city->getCityName());
    	$city_text = htmlspecialchars($city->getCityText());
 
		$stmnt = $this->_db->prepare($sql);
 
		$stmnt->bindParam(':city_id', $city_id = $_GET['city_id']);
		$stmnt->bindParam(':city_name', $city_name);
		$stmnt->bindParam(':city_text', $city_text);
 
		$stmnt->execute();
 
		$city_data = $stmnt->fetch(PDO::FETCH_ASSOC);
 
		$cities_data[] = $city_data;
 
		return $cities_data;
    }
class/City.php

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
 
class City {
 
    protected $city_id;
    protected $city_name;
    protected $city_text;
 
	protected static $error;
 
    const MSG_ERROR_CITY_ID = 'CITY ID doit être un entier';
	const MSG_ERROR_CITY_NAME = 'CITY NAME doit être une chaîne de caractères';
	const MSG_ERROR_CITY_TEXT = 'CITY TEXT doit être une chaîne de caractères';
	const MSG_ERROR_OBJET = 'L\'OBJET ne peut pas être crée';
 
	public function __construct(array $data) {
 
        $this->setCityId($data['city_id']);
		$this->setCityName($data['city_name']);
		$this->setCityText($data['city_text']);
 
		if(!empty(self::$error)) {
 
        	throw new Exception(self::$error . self::MSG_ERROR_OBJET);
        }
	}
 
    public function setError($msg) {
 
		self::$error = $msg;
	}
 
	public function getError() {
 
		return self::$error;
	}
 
	public function setCityId($city_id) {
 
		if((is_int($city_id)) AND ($city_id > 0)) {
 
			$this->city_id = $city_id;
		}
		else {
 
			$this->setError(self::MSG_ERROR_CITY_ID);
		}
	}
 
	public function setCityName($city_name) {
 
		if(is_string($city_name)) {
 
			$this->city_name = $city_name;
		}
		else {
 
			$this->setError(self::MSG_ERROR_CITY_NAME);
		}
	}
 
	public function setCityText($city_text) {
 
		if(is_string($city_text)) {
 
			$this->city_text = $city_text;
		}
		else {
 
			$this->setError(self::MSG_ERROR_CITY_TEXT);
		}
	}
 
	public function getCityId() {
 
		return $this->city_id;
	}
 
	public function getCityName() {
 
		return $this->city_name;
	}
 
	public function getCityText() {
 
		return $this->city_text;
	}
}
admin/index.php

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
 
<?php
 
require('../includes/inc-connexion.php');
require('../class/cityManager.php');
 
?>
 
<!DOCTYPE html>
 
<html lang="fr">
     <head>
          <meta charset="utf-8">
          <title>Accueil Administration</title>
          <link rel="stylesheet" href="css/style.css">
     </head>
 
     <body>
          <div id="wrapper">
              <h1>Administration du mini-site des villes</h1>
              <div id="bloc_left">
              	  <p>
                     L'administration du site vous permet d'ajouter<br>
                     une nouvelle ville au site ou de modifier ou<br>
                     supprimer une ville existante.
                  </p>
              </div>
 
              <div id="bloc_right">
              	  <ul>
              	  	 <li><a href="insert-city.php">Ajouter une ville</a></li>
              	  	 <li><a href="../index.php">Voir le site</a></li>
                     <li><a href="logout.php">Déconnexion</a></li>
              	  </ul>
              </div>
 
              <p>Liste des villes : </p>
 
              <?php 
 
              $manager = new cityManager($db);
              $cities_data = $manager->getDisplayCities();
 
              ?>
 
              <div id="menu_vertical">
                <ul>
                  <li><a href="../index.php">Accueil</a></li>
                  <?php if(!empty($cities_data)) : ?>
                    <?php foreach($cities_data as $city_data) : ?>
                      <li>
                        <a href="../city.php?city_id=<?php echo $city_data['city_id'] ?>"><?php echo $city_data['city_name'] ?></a> -
                        <a href="update-city.php?city_id=<?php echo $city_data['city_id'] ?>">[editer]</a> -
                        <a href="delete-city.php?city_id=<?php echo $city_data['city_id'] ?>">[supprimer]</a>
                      </li>
                    <?php endforeach ?>
                  <?php endif ?>
                </ul>
              </div>
          </div>
        </body>
</html>
admin/update-city.php

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
 
<?php
 
require('../includes/inc-connexion.php');
require('../process/process-update-city.php');
 
$cities_data = array(
 
	'city_id' => $city_id,
	'city_name' => $city_name,
	'city_text' => $city_text
);
 
$city_data = new City($cities_data);
 
$manager = new cityManager($db);
$cities_data = $manager->getDisplayCity($city_data);
 
?>
 
<!DOCTYPE html>
 
<html lang="fr">
 
<head>
	<title>Modifier une ville</title>
	<meta charset="utf-8">
	<link rel="stylesheet" href="css/style.css">
</head>
 
<body>
	<div id="wrapper">
		<h1>Modifier une ville</h1>
		<form action="" method="post">
			<table>
				<?php if(!empty($cities_data)) : ?>
					<?php foreach($cities_data as $city_data) : ?>
						<tr>
							<td>
								<input type="text" id="city_name" name="city_name_form" placeholder="Nom de ville"
						               value="<?php echo $city_data['city_name'] ?>">
					        </td>
				        </tr>
 
				        <tr>
					       <td><label for="city_text">Texte de présentation</label></td>
				        </tr>
 
				        <tr>	
					       <td>
					       	<textarea rows="25" cols="50" id="city_text" name="city_text_form">
					       	<?php echo $city_data['city_text'] ?>
 
						    </textarea>
					       </td>
				        </tr>
 
				        <tr>
					       <td><input type="reset" value="Remise à zéro du formulaire"></td>
				        </tr>
 
				        <tr>
					       <td><input type="submit" id="submit" name="submit_form" value="Modifier la ville"></td>
				        </tr>
				    <?php endforeach ?>
				<?php endif ?>
			</table>
		</form>
 
		<?php if(isset($message)) echo $message ?>
	</div>
</body>
 
</html>
process/process-update-city.php

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
 
require('../includes/inc-connexion.php');
require('../class/City.php');
require('../class/cityManager.php');
 
if(isset($_POST['submit_form'])) {
 
  $city_name_form = trim($_POST['city_name_form']);
  $city_text_form = trim($_POST['city_text_form']);
 
  if((empty($city_name_form)) OR (empty($city_text_form))) {
 
    $message = '<p class="error">Veuillez remplir tous les champs !</p>';
  }
  else {
 
  	$data_city = array(
 
  		'city_name' => $city_name_form,
  		'city_text' => $city_text_form
  	);
 
  	$data_cities = new City($data_city);
 
  	$manager = new cityManager($db);
 
    if(!$manager->getCity($city_name_form, $city_text_form)) {
 
      $message = '<p class="error">La ville ' . $city_name_form . ' n\'a pas été mise à jour !</p>';
    }
    else {
 
      $manager->updateCity($data_cities);
 
      $message = '<p class="success">La ville ' . $city_name_form . ' a été mise à jour !</p>';
    }
  }
}