Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. // Connexion à la BDD
  4. $link = mysqli_connect('127.0.0.1', 'root', '', 'csiw');
  5.  
  6. if (! $link) { // On vérifie si le lien à la BDD est fonctionnel
  7.     die('Error : could not connect to database. ' . mysqli_connect_error());
  8. }
  9.  
  10. $query = 'SELECT * FROM users'; // la requête pour récuperer le sinfos de la table
  11.  
  12. ?>
  13.  
  14. <!DOCTYPE html>
  15. <html lang="en" dir="ltr">
  16. <head>
  17.     <meta charset="utf-8">
  18.     <title>Utilisateurs</title>
  19. </head>
  20. <body>
  21.  
  22. <?php
  23.  
  24.     // Si le formulaire a été soumis
  25.     if (isset($_GET['user'])) {
  26.         // On affiche l'ID
  27.         echo 'ID : ' . $_GET['user'];
  28.     }
  29.  
  30. ?>
  31.  
  32. <form action="index.php" method="get">
  33.  
  34.  
  35.         <?php if ($result = mysqli_query($link, $query) AND mysqli_num_rows($result) > 0) { ?>
  36.  
  37.         <select name="user" id="user">
  38.  
  39.             <?php
  40.                 while ($row = mysqli_fetch_row($result)) {
  41.                     echo '<option value="' . $row[0] . '">' .$row[1] . ' ' . $row[2]  . '</option>';
  42.                 }
  43.             ?>
  44.  
  45.         </select>
  46.  
  47.         <button type="submit">Soumettre</button>
  48.  
  49.         <?php
  50.         } else {
  51.             echo "Personne dans la BDD";
  52.         }
  53.         ?>
  54.  
  55.  
  56.  
  57.  
  58. </form>
  59.  
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement