1-l'attribut action dans la "form" doit contenir le chemin du fichier php, vers lequel les données seront envoyées.
<form method="GET" action="chemin_relatif_au_fichier_php">
2-dès que les données sont bien reçues, il faut les stocker dans une variable, selon ton code t'utilise $compte mais c'est faux, il faut utiliser une autre variable (corrige ton code html).
index1.php :
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
|
<table border="0" width="50%">
<tr>
<td><!-- la form dans la td et pas le contraire!-->
<form method="GET" action="test.php">
<SELECT name="pays1">
<OPTION value="KSA" >Arabie Saoudite</OPTION>
<OPTION value="AFG">Afghanistan</OPTION>
<OPTION value="BAN">Bangladesh</OPTION>
</SELECT>
<SELECT name="pays2">
<OPTION value="KSA">Arabie Saoudite</OPTION>
<OPTION value="AFG">Afghanistan</OPTION>
<OPTION value="BAN">Bangladesh</OPTION>
</SELECT>
<input type="submit" value="OK"/>
</form>
</td>
</tr>
<?php
if(isset($_GET['data'])){
$the_data=unserialize($_GET['data']);
?>
<tr>
<td>Compte :<?=$the_data['tout'];?></td>
<td>Pays 1 :<?=$the_data['pays1']?></td>
<td>Pays 2 :<?=$the_data['pays2']?></td>
</tr>
<?php }?>
</table> |
test.php :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
$bdd=new PDO('mysql:host=localhost;dbname=nom_de_la_base', 'ton_rout', 'ton_mot_de_passe', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$compte= $bdd->prepare("SELECT COUNT(*) as tout FROM head2head
WHERE
(`pays1`=:P1 and `pays2`=:P2)
or (`pays1`=:P2 and `pays2`=:P1)
");
$compte->execute(array(
':P1' => $_GET['pays1'], //n'oublis pas les deux points (:) avant P1
':P2' => $_GET['pays2']//n'oublis pas les deux points (:) avant P2
));
$data=$compte->fetch(PDO::FETCH_ASSOC);//stocker le résultat dans $data
$data['pays1']=$_GET['pays1'];//on ajoute le paramètre pays1 dans $data
$data['pays2']=$_GET['pays2'];//on ajoute le paramètre pays2 dans $data
header('Location:index1.php?data='.serialize($data));//redirection vers la page du formulaire avec $data |
Partager