noam76

edit_invoice.php

May 11th, 2023
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. // Page de modification des factures
  2.  
  3. <?php
  4. session_start();
  5. include 'config.php';
  6.  
  7. if(!isset($_SESSION['username'])) {
  8.     header('Location: login.php');
  9.     exit();
  10. }
  11.  
  12. $id = $_GET['id'];
  13.  
  14. $query = "SELECT * FROM invoices WHERE id = '$id'";
  15. $result = mysqli_query($con, $query);
  16. $row = mysqli_fetch_array($result);
  17.  
  18. if(isset($_POST['submit'])) {
  19.     $date = $_POST['date'];
  20.     $appartement = $_POST['appartement'];
  21.     $montant = $_POST['montant'];
  22.     $status = $_POST['status'];
  23.  
  24.     $query = "UPDATE invoices SET date = '$date', appartement = '$appartement', montant = '$montant', status = '$status' WHERE id = '$id'";
  25.  
  26.     if(mysqli_query($con, $query)) {
  27.         header('Location: invoices.php');
  28.         exit();
  29.     } else {
  30.         echo "<script>alert('Une erreur est survenue lors de la modification de la facture.')</script>";
  31.     }
  32. }
  33.  
  34. ?>
  35.  
  36. <!DOCTYPE html>
  37. <html>
  38. <head>
  39.     <title>Finance - Modifier une facture</title>
  40.     <link rel="stylesheet" type="text/css" href="style.css">
  41. </head>
  42. <body>
  43.     <div class="header">
  44.         <h2>Modifier une facture</h2>
  45.     </div>
  46.     <div class="navbar">
  47.         <a href="home.php">Accueil</a>
  48.         <a href="payments.php">Paiments</a>
  49. <a href="invoices.php">Factures</a>
  50. <a href="logout.php" style="float:right">Déconnexion</a>
  51. </div>
  52. <form method="post" action="">
  53. <div class="input-group">
  54. <label>Date :</label>
  55. <input type="date" name="date" value="<?php echo $row['date']; ?>">
  56. </div>
  57. <div class="input-group">
  58. <label>Appartement :</label>
  59. <?php
  60.              $query = "SELECT * FROM proprietaires ORDER BY nom ASC";
  61.              $result = mysqli_query($con, $query);
  62.              $options = "";
  63.              while($proprio = mysqli_fetch_array($result)) {
  64.                  $selected = ($row['appartement'] == $proprio['appartement']) ? "selected" : "";
  65.                  $options .= "<option value='".$proprio['appartement']."' ".$selected.">".$proprio['appartement']." - ".$proprio['nom']." ".$proprio['prenom']."</option>";
  66.              }
  67.          ?>
  68. <select name="appartement">
  69. <option value="">Sélectionner un appartement</option>
  70. <?php echo $options; ?>
  71. </select>
  72. </div>
  73. <div class="input-group">
  74. <label>Montant :</label>
  75. <input type="text" name="montant" value="<?php echo $row['montant']; ?>">
  76. </div>
  77. <div class="input-group">
  78. <label>Status :</label>
  79. <select name="status">
  80. <option value="payée" <?php if($row['status'] == "payée") echo "selected"; ?>>Payée</option>
  81. <option value="en_attente" <?php if($row['status'] == "en_attente") echo "selected"; ?>>En attente</option>
  82. <option value="en_retard" <?php if($row['status'] == "en_retard") echo "selected"; ?>>En retard</option>
  83. </select>
  84. </div>
  85. <div class="input-group">
  86. <button type="submit" class="btn" name="submit">Modifier la facture</button>
  87. </div>
  88. </form>
  89.  
  90. </body>
  91. </html>
  92.  
Add Comment
Please, Sign In to add comment