noam76 icon

edit_invoice.php

noam76 | PRO | 05/11/23 06:12:18 AM UTC | 0 ⭐ | 469 👁️ | Never ⏰ | []
PHP |

2.82 KB

|

None

|

0 👍

/

0 👎

// Page de modification des factures
 
<?php
session_start();
include 'config.php';
 
if(!isset($_SESSION['username'])) {
    header('Location: login.php');
    exit();
}
 
$id = $_GET['id'];
 
$query = "SELECT * FROM invoices WHERE id = '$id'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_array($result);
 
if(isset($_POST['submit'])) {
    $date = $_POST['date'];
    $appartement = $_POST['appartement'];
    $montant = $_POST['montant'];
    $status = $_POST['status'];
 
    $query = "UPDATE invoices SET date = '$date', appartement = '$appartement', montant = '$montant', status = '$status' WHERE id = '$id'";
 
    if(mysqli_query($con, $query)) {
        header('Location: invoices.php');
        exit();
    } else {
        echo "<script>alert('Une erreur est survenue lors de la modification de la facture.')</script>";
    }
}
 
?>
 
<!DOCTYPE html>
<html>
<head>
    <title>Finance - Modifier une facture</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div class="header">
        <h2>Modifier une facture</h2>
    </div>
    <div class="navbar">
        <a href="home.php">Accueil</a>
        <a href="payments.php">Paiments</a>
<a href="invoices.php">Factures</a>
<a href="logout.php" style="float:right">Déconnexion</a>
</div>
<form method="post" action="">
<div class="input-group">
<label>Date :</label>
<input type="date" name="date" value="<?php echo $row['date']; ?>">
</div>
<div class="input-group">
<label>Appartement :</label>
<?php
             $query = "SELECT * FROM proprietaires ORDER BY nom ASC";
             $result = mysqli_query($con, $query);
             $options = "";
             while($proprio = mysqli_fetch_array($result)) {
                 $selected = ($row['appartement'] == $proprio['appartement']) ? "selected" : "";
                 $options .= "<option value='".$proprio['appartement']."' ".$selected.">".$proprio['appartement']." - ".$proprio['nom']." ".$proprio['prenom']."</option>";
             }
         ?>
<select name="appartement">
<option value="">Sélectionner un appartement</option>
<?php echo $options; ?>
</select>
</div>
<div class="input-group">
<label>Montant :</label>
<input type="text" name="montant" value="<?php echo $row['montant']; ?>">
</div>
<div class="input-group">
<label>Status :</label>
<select name="status">
<option value="payée" <?php if($row['status'] == "payée") echo "selected"; ?>>Payée</option>
<option value="en_attente" <?php if($row['status'] == "en_attente") echo "selected"; ?>>En attente</option>
<option value="en_retard" <?php if($row['status'] == "en_retard") echo "selected"; ?>>En retard</option>
</select>
</div>
<div class="input-group">
<button type="submit" class="btn" name="submit">Modifier la facture</button>
</div>
</form>
 
</body>
</html>
 

Comments