<?php
session_start();
include 'config.php';
if(!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
if(isset($_POST['submit'])) {
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$appartement = $_POST['appartement'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$query = "INSERT INTO proprietaires (nom, prenom, appartement, telephone, email) VALUES ('$nom', '$prenom', '$appartement', '$telephone', '$email')";
if(mysqli_query($con, $query)) {
echo "<script>alert('Le propriétaire a été ajouté avec succès.')</script>";
} else {
echo "<script>alert('Une erreur est survenue lors de l\'ajout du propriétaire.')</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Gestion des propriétaires</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Gestion des propriétaires</h2>
</div>
<div class="navbar">
<a href="home.php">Accueil</a>
<a href="invoices.php">Factures</a>
<a href="owners.php">Propriétaires</a>
<a href="finance.php">Finance</a>
<a href="logout.php" style="float:right">Déconnexion</a>
</div>
<form method="post" action="owners.php">
<div class="input-group">
<label>Nom :</label>
<input type="text" name="nom" required>
</div>
<div class="input-group">
<label>Prénom :</label>
<input type="text" name="prenom" required>
</div>
<div class="input-group">
<label>Appartement :</label>
<input type="text" name="appartement" required>
</div>
<div class="input-group">
<label>Téléphone :</label>
<input type="text" name="telephone" required>
</div>
<div class="input-group">
<label>Email :</label>
<input type="email" name="email" required>
</div>
<div class="input-group">
<button type="submit" class="btn" name="submit">Ajouter</button>
</div>
</form>
<br>
<table>
<thead>
<tr>
<th>Nom</th>
<th>Prénom</th>
<th>Appartement</th>
<th>Téléphone</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM proprietaires ORDER BY nom ASC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['nom'] . "</td>";
echo "<td>" . $row['prenom'] . "</td>";
echo "<td>" . $row['appartement'] . "</td>";
echo "<td>" . $row['telephone'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
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>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>
Comments