Advertisement
noam76

owners.php

May 11th, 2023
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include 'config.php';
  4.  
  5. if(!isset($_SESSION['username'])) {
  6.     header('Location: login.php');
  7.     exit();
  8. }
  9.  
  10. if(isset($_POST['submit'])) {
  11.     $nom = $_POST['nom'];
  12.     $prenom = $_POST['prenom'];
  13.     $appartement = $_POST['appartement'];
  14.     $telephone = $_POST['telephone'];
  15.     $email = $_POST['email'];
  16.  
  17.     $query = "INSERT INTO proprietaires (nom, prenom, appartement, telephone, email) VALUES ('$nom', '$prenom', '$appartement', '$telephone', '$email')";
  18.  
  19.     if(mysqli_query($con, $query)) {
  20.         echo "<script>alert('Le propriétaire a été ajouté avec succès.')</script>";
  21.     } else {
  22.         echo "<script>alert('Une erreur est survenue lors de l\'ajout du propriétaire.')</script>";
  23.     }
  24. }
  25.  
  26. ?>
  27.  
  28. <!DOCTYPE html>
  29. <html>
  30. <head>
  31.     <title>Gestion des propriétaires</title>
  32.     <link rel="stylesheet" type="text/css" href="style.css">
  33. </head>
  34. <body>
  35.     <div class="header">
  36.         <h2>Gestion des propriétaires</h2>
  37.     </div>
  38.     <div class="navbar">
  39.         <a href="home.php">Accueil</a>
  40.         <a href="invoices.php">Factures</a>
  41.         <a href="owners.php">Propriétaires</a>
  42.         <a href="finance.php">Finance</a>
  43.         <a href="logout.php" style="float:right">Déconnexion</a>
  44.     </div>
  45.     <form method="post" action="owners.php">
  46.         <div class="input-group">
  47.             <label>Nom :</label>
  48.             <input type="text" name="nom" required>
  49.         </div>
  50.         <div class="input-group">
  51.             <label>Prénom :</label>
  52.             <input type="text" name="prenom" required>
  53.         </div>
  54.         <div class="input-group">
  55.             <label>Appartement :</label>
  56.             <input type="text" name="appartement" required>
  57.         </div>
  58.         <div class="input-group">
  59.             <label>Téléphone :</label>
  60.             <input type="text" name="telephone" required>
  61.         </div>
  62.         <div class="input-group">
  63.             <label>Email :</label>
  64.             <input type="email" name="email" required>
  65.         </div>
  66.         <div class="input-group">
  67.             <button type="submit" class="btn" name="submit">Ajouter</button>
  68.         </div>
  69.     </form>
  70.     <br>
  71.     <table>
  72.         <thead>
  73.             <tr>
  74.                 <th>Nom</th>
  75.                 <th>Prénom</th>
  76.                 <th>Appartement</th>
  77.                 <th>Téléphone</th>
  78.                 <th>Email</th>
  79.                             <th>Actions</th>
  80.             </tr>
  81.         </thead>
  82.         <tbody>
  83.             <?php
  84.             $query = "SELECT * FROM proprietaires ORDER BY nom ASC";
  85.             $result = mysqli_query($con, $query);
  86.  
  87.             while($row = mysqli_fetch_array($result)) {
  88.                 echo "<tr>";
  89.                 echo "<td>" . $row['nom'] . "</td>";
  90.                 echo "<td>" . $row['prenom'] . "</td>";
  91.                 echo "<td>" . $row['appartement'] . "</td>";
  92.                 echo "<td>" . $row['telephone'] . "</td>";
  93.                 echo "<td>" . $row['email'] . "</td>";
  94.                 echo "<td><a href='edit_owner.php?id=" . $row['id'] . "' class='edit_btn'>Modifier</a> <a href='delete_owner.php?id=" . $row['id'] . "' class='del_btn'>Supprimer</a></td>";
  95.                 echo "</tr>";
  96.             }
  97.             ?>
  98.         </tbody>
  99.     </table>
  100. </body>
  101. </html>        
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement