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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// (Je passe tous les tests et les connexions en base car tout ça fonctionne [...] ;)
if (!isset($_POST['continent'])) { $_POST['continent'] = '';}
// Retour après choix du SELECT Continent
if(isset($_POST['continent']) && ($_POST['continent'] <> '')) {
$_SESSION['continent'] = $_POST['continent'];
$_SESSION['continent'] = Remplace_Char($j,$i,$_SESSION['continent']);
echo $_SESSION['continent'].' Session continent<br>';
}
// Retour après choix du SELECT PAYS
if (!isset($_POST['pays'])) { $_POST['pays'] = ''; }
if(isset($_POST['pays']) || isset($_SESSION['pays'])) {
$_SESSION['pays'] = $_POST['pays'];
$_SESSION['pays'] = Remplace_Char($j,$i,$_SESSION['pays']);
echo $_SESSION['continent'].' Session continent<br>';
echo $_SESSION['pays'].' Session pays<br>';
}
// Retour après saisie de la ville
if(isset($_POST['ville']) && ($_POST['ville'] <> '')) {
$ville = $_POST['ville'];
$sql = "SELECT * FROM villes WHERE ville = '$ville'";
$req = ExecReq($sql); // Fonction créée pour appel plus rapide à la requête
$res = NbLigne($req); // Idem que prédemment
// Si la ville n'existe pas
if ($res <> 0) {
// On récupère les identifiants des données récupérées dans les sessions
if (isset($_SESSION['continent']) && isset($_SESSION['pays'])) {
$continent = $_SESSION['continent'];
$pays = $_SESSION['pays'];
$sql2 = "SELECT p.id_pays, c.id_continent FROM pays p, continent c
WHERE c.continent = '$continent'
AND p.pays = '$pays';";
$req2 = ExecReq($sql2);
while ($data = mysql_fetch_array($req)) {
$id_continent = $data['id_continent'];
$id_pays = $data["id_pays"];
}
// On insère la donnée ville en base.
$sql3 = "INSERT INTO ville VALUE ('','$ville', $id_pays', '$id_continent');";
$req3 = ExecReq($sql3);
echo $sql3;
echo 'Vous avez intétégré la ville $ville en base.<br />';
include('fiche_villes.php');
exit;
}
}
else {
echo "La ville saisie existe déjà";
include('fiche_villes.php');
exit;
}
}
[...] Je passe également la partie HTML avec les en-têtes, appel CSS car par important... [...] ;)
<FORM method="post" action="">
<div align="center" id="entete" class="cache">
<img src="../images/logo.png" height="53" width="400">
<div align="right"><a href="../includes/deconnexion.php">Déconnexion</a></div>
</div>
<div align="center" valign="middle" id="corps">
<br><a href="../accueil/accueil.php" class="cache">Retour</a><br><br>
<fieldset><legend>Ajouter une ville :</legend>
<br><br>
<FORM method="post" action="">
<table id="table" class="print">
<TR><TD>Continent :</TD><TD>
<form id="id_continent" method="post" action="">
<select id="continent" name="continent" onchange="this.form.submit()"> :calim2:
<!--ICI c'est un test de this.form.submit car le document.forms ne renvoie rien || onchange="document.forms['id_continent'].submit();"-->
<?php
$sql = "SELECT * FROM continent ORDER BY continent ASC";
$req = ExecReq($sql);
if (isset($_SESSION['continent'])) {
$data['continent'] = Remplace_Char($j,$i,$data['continent']);
echo "<option selected=".$_SESSION['continent'].">".$_SESSION['continent']."</option>";
$sql = "SELECT * FROM continent ORDER BY continent ASC";
$req = ExecReq($sql);
while ($data = mysql_fetch_array($req)) {
$data['continent'] = Remplace_Char($i,$j,$data['continent']);
if ($_SESSION['continent'] <> $data['continent']) {
echo "<option value=".$data['continent'].">".$data['continent']."</option>";
}
}
}
else {
$sql = "SELECT * FROM continent ORDER BY continent ASC";
$req = ExecReq($sql);
while ($data = mysql_fetch_array($req)) {
$data['continent'] = Remplace_Char($i,$j,$data['continent']);
echo "<option value=".$data['continent'].">".$data['continent']."</option>";
}
}
?>
</select>
</form>
</td></tr>
<form id="id_pays" method="post" action="">
<tr><td>Pays :</td><td>
<select name="pays" id="pays" onchange="document.forms['id_pays'].submit();"> // Et la ça fonctionne :_\
<?php
if (isset($_SESSION['continent'])) {
$continent = $_SESSION['continent'];
if (isset($_SESSION['pays'])) {
echo "<option selected=".$_SESSION['pays'].">".$_SESSION['pays']."</option>";
$sql2 = "SELECT * FROM pays p, continent c
WHERE c.continent = '$continent'
AND c.id_continent = p.id_continent;";
$req2 = ExecReq($sql2);
while ($data = mysql_fetch_array($req2)) {
$data['pays'] = Remplace_Char($i,$j,$data['pays']);
echo "<option value=".$data['pays'].">".$data['pays']."</option>";
}
}
else {
$sql2 = "SELECT * FROM pays p, continent c
WHERE c.continent = '$continent'
AND c.id_continent = p.id_continent;";
$req2 = ExecReq($sql2);
while ($data = mysql_fetch_array($req2)) {
$data['pays'] = Remplace_Char($i,$j,$data['pays']);
echo "<option value=".$data['pays'].">".$data['pays']."</option>";
}
}
}
echo "</select></td></tr></form><tr><td>Ville :</td><td><input type=text name=ville value=$ville></td></tr>";
Deconnexion();
?>
</table>
<br><br>
<div align="center"><input type="submit" name="valider" value="Ajouter"></div>
</fieldset>
</FORM> |
Partager