Bonjour à tous,
J'ai un soucis avec mon formulaire javascript pour une requete php si quelqu'un peut m'aider,
ce que je veux faire c'est quand je clique sur homme ou femme, je recois un tableau avec nom prenom sexe homme ou femme
voilà je vous presente ma page html
et voici mon 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 <!DOCTYPE html> <html lang="fr"> <head> <title>PHP EX requête ()</title> <meta charset="UTF-8"> <style type="text/css"> </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> function choix0(){ var choix=document.getElementById("choix").value; var xhr=$.ajax({ url:'BDD2.php', type:'POST', data:{sexe:choix}, dataType: 'html' }) .done (function(data) { var liste=data; alert(liste); }).fail(function() { var err ='erreur '+jqXHR.statusCode() + ' status '+ jqXHR.status +' '+jqXHR.statusText; //alert(err) $("#result").text(err); }).done (function(data) { }) }; </script> </head> <body> <h3>Résultats</h3> <label for="choix">catagorie :</label> <select id="choix" > <option id="choix1" value="M" name="homme" selected > homme</option> <option id="choix2"= value="F" name="femme">femme</option> <input id="valider" type="button" value=" valider " onclick="choix0()" /> </select> <div id="result"> <div id="liste"> </div> </div> </body> </html>
Code php : 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 <?PHP session_start(); $connexion = 'mysql:host=localhost;dbname=bourges'; $user = "MDF"; $mdp = "mdf"; try { $dbh = new PDO($connexion, $user, $mdp); $flag_connect = 'connexion effectuée'; } catch (PDOException $e) { print "Erreur !: " . $e->getMessage() . "<br/>"; die(); } ?> <!DOCTYPE html> <html lang="fr"> <head> <title>PHP EX86 fetchAll()</title> <meta charset="UTF-8"> <style type="text/css"> </style> <script type="text/javascript"> </script> </head> <body> <h3>Résultats</h3> <?PHP $query = "SELECT nom, prenom, sexe FROM adherents ORDER BY nom"; try { $cmd = $dbh->prepare($query); $cmd->execute(); $cmd->bindColumn(1,$nom); $cmd->bindColumn(2,$prenom); $cmd->bindColumn(3,$sexe); echo "<table>\n"; echo "<tr><td>Nom</td><td>Prénom</td><td>sexe</td></tr>\n"; while ($enreg = $cmd->fetch(PDO::FETCH_BOUND)) { echo "<tr><td>".$nom."</td><td>".htmlentities($prenom)."</td><td>".htmlentities($sexe)."</td></tr>\n"; } echo "</table>\n"; } catch (PDOException $e) { print $e->getMessage(); } ?> </body> </html>
merci pour vos réponse
Partager