[PHP-JS] Rediriger vers une autre page
Bonjour à tous
A un endroit dans une page, j'aimerai redirigé sur ma page (en faite recharger ma page) lorsque je click sur mon bouton de formulaire RESET.
Code:
1 2 3 4 5 6 7 8
|
<input type="submit" name="reset" id="reset" value="Annuler">
</form>
<? if (isset($_POST['reset'])) {
// response.redirect "liste.asp"
}
?> |
Quelqu'un pourrait me dire quelle instruction en PHP correspond à l'instruction ASP suivante:
response.redirect "ma_page.asp" (permet de rediriger vers ma_page.asp)
De plus lorsque que je click sur le bouton actualiser (barre d'outils d'internet explorer) ma page plante.
Comment faire pour éviter ce plantage? (j'ai entendu parler d'un fonction header("location....) mais je n'arrive pas à l'utiliser. Ca plante tout le temps et de plus ça me met encore un message d'erreur..) J'ai vraiment rien compris avec cette fonction header..
Merci d'avance.
Ci-dessous le code complet de ma page qui marche très bien sauf la redirection et l'actualisation..
Code:
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
<html>
<head>
<? // Fonctions diverses
function selectMenuWithConstant($value, $selectedValue)
{
If ($value==$selectedValue) {
$retour = "selected";
return $retour;
}
else
{
$retour = "";
return $retour;
}
}
// Paramètres perso
$host = "localhost"; // voir hébergeur
$user = "***"; // vide ou "root" en local
$pass = "***"; // vide en local
$bdd = "mysql"; // nom de la BD
// Connection au serveur
@mysql_connect($host,$user,$pass)
or die("Impossible de se connecter");
// connection à la base
@mysql_select_db("$bdd")
or die("Impossible de se connecter");
?>
</head>
<body>
<? // propre au paging et au critère
//récupération des paramètres
$FORM_FPARAM_01 = @$_POST["FParam_01"];
$URL_PARAM_01 = @$_GET["Param_01"];
$FORM_FPARAM_01_VALUE = @$_POST["FParam_01_value"];
$URL_PARAM_01_VALUE = @$_GET["Param_01_value"];
If (($URL_PARAM_01 != "") && ($FORM_FPARAM_01 == "")) {
$valeur1 = $URL_PARAM_01;
}
Else {
$valeur1 = $FORM_FPARAM_01;
}
If (($URL_PARAM_01_VALUE != "") && ($FORM_FPARAM_01_VALUE == "")) {
$valeur2 = $URL_PARAM_01_VALUE;
}
Else {
$valeur2 = $FORM_FPARAM_01_VALUE;
}
$strParam = "";
$strWhere = "";
$isValue = false;
// Paramètre personnalisé "Param_01"
If ((strlen($valeur1)>0) && (strlen($valeur2)>0)) {
If ($isValue==true) {
$strWhere = "$strWhere AND";
}
Else
$strWhere = "$strWhere WHERE";{
}
$isValue = true;
//strTemp_01 = replace(valeur2,"*","%")
$JOCKER = "%'";
$strTemp_01 = $valeur2;
$strWhere = "$strWhere $valeur1 LIKE '$strTemp_01$JOCKER";
$strParam = "$strParam&Param_01=$valeur1&Param_01_value=$valeur2";
}
$SQL = "Select * from fiche $strWhere";
$SQLT = "select * from fiche";
//Initialisation du premier numéro de page
$page = @$_GET["num"];
$NbElementParPage = 10;
// valeur par défaut
$intRecordCount=0;
$result = mysql_query($SQL);
while ($val = mysql_fetch_array($result)) {
$intRecordCount = mysql_numrows($result);
}
$intPageCount = ceil($intRecordCount/$NbElementParPage);
if ((int) $page > (int) $intPageCount) {
$page = $intPageCount;
}
if ((int) $page <= 0) {
$page = 1;
}
?>
<FORM name = "form1" method="post" action="?num=<? echo $page; ?><? echo $strParam ?>">
<select name="FParam_01" size="1">
<option selected value="nom" <? echo selectMenuWithConstant("nom", $valeur1);?>>Nom</option>
<option value="prenom" <? echo selectMenuWithConstant("prenom", $valeur1);?>>Prénom</option>
<option value="localite" <? echo selectMenuWithConstant("localite", $valeur1)?>>Localité</option>
</select>
<input name="FParam_01_value" type="text" size="40" maxlength="30" value="<? echo $valeur2; ?>">
<input type="submit" id="soumission" value="Soumettre">
<input type="submit" name="reset" id="reset" value="Annuler">
</form>
<? if (isset($_POST['reset'])) {
// response.redirect "liste.asp"
}
?>
<br>
<br>
<table width="100%" cellspacing="2" cellpadding="0" border="0">
<tr>
<td valign="top" align="left">
<? echo $intRecordCount;?> enregistrement(s)
<? If (($intRecordCount > 0) && ((int) $intPageCount > 1)){ ?>
<? If ((int) $page > 1) { ?>
<a href="?num=<? echo $page-1; ?><? echo $strParam; ?>"><< Précédent</a>
<? } ?>
<? For ($i = 1; $i<=(int) $intPageCount; $i++) { ?>
<? If ($i == $page) { ?>
<b><? echo $i;?></b>
<? } Else {?>
<a href="?num=<? echo $i;?><? echo $strParam ?>"><? echo $i;?></a>
<? } ?>
<? } ?>
<? If ((Int) $page < (Int) $intPageCount) { ?>
<a href="?num=<? echo $page+1;?><? echo $strParam;?>">Suivant >></a>
<? } ?>
<? } ?>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0">
<tr>
<td width="70"><strong>Numéro</strong></td>
<td width="180"><strong>Nom</strong></td>
<td width="150"><strong>Prénom</strong></td>
<td width="250"><strong>Adresse</strong></td>
<td width="250"><strong>Localité</strong></td>
</tr>
<?
$result = mysql_query($SQL);
$debut = (($page-1)*$NbElementParPage);
$cur = 0;
while (($val = mysql_fetch_array($result)) && ($cur < $debut+$NbElementParPage)) {
//pour savoir si elle est à afficher
if ($cur >= $debut) {
if ($cur % 2 == 0) { ?>
<tr>
<td bgcolor="#2199A8"><? echo $val["numero"]; ?></td>
<td bgcolor="#2199A8"><a href="affichage.asp?num=<? echo $val["nom"]; ?>"><? echo $val["nom"]; ?></a></td>
<td bgcolor="#2199A8"><? echo $val["prenom"]; ?></td>
<td bgcolor="#2199A8"><? echo $val["adresse"]; ?></td>
<td bgcolor="#2199A8"><? echo $val["localite"]; ?></td>
</tr>
<? } else { ?>
<tr>
<td><? echo $val["numero"]; ?></td>
<td><a href="affichage.asp?num=<? echo $val["nom"]; ?>"><? echo $val["nom"]; ?></a></td>
<td><? echo $val["prenom"]; ?></td>
<td><? echo $val["adresse"]; ?></td>
<td><? echo $val["localite"]; ?></td>
</tr>
<? }
}
//on incrémente le conteur
$cur = $cur + 1;
} ?>
</table>
<?
mysql_close();
?>
<br>
<br>
<a href="../index.htm">Retour</a>
</body>
</html> |