You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
3.8 KiB

<?php
/**
* Use an HTML form to create a new entry in the
* users table.
*
*/
require './config.php';
require './common.php';
$success = null;
if (isset($_POST["submit"])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$identificador = $_POST["submit"];
$sql = "DELETE FROM vehiculos WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->bindValue(':identificador', $identificador);
$statement->execute();
$success = "Vehículo borrado con éxito";
$log_msg='BORRA VEHÍCULO-> ID: '.$identificador;
escribe_log($log_msg);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT * FROM vehiculos";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
require "./cabecera.php";?>
<div class="app-wrapper">
<div class="app-content pt-3 p-md-3 p-lg-4">
<div class="container-xl">
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<h1 class="app-page-title mb-0">Borrar vehículo</h1>
</div>
</div><!--//row-->
<?php if ($success) echo $success; ?>
<div class="tab-content" id="orders-table-tab-content">
<div class="tab-pane fade show active" id="orders-all" role="tabpanel" aria-labelledby="orders-all-tab">
<div class="app-card app-card-orders-table shadow-sm mb-5">
<div class="app-card-body">
<div class="table-responsive">
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell">#</th>
<th class="cell">Marca</th>
<th class="cell">Modelo</th>
<th class="cell">Matrícula</th>
<th class="cell">Borrar</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td class="cell"><?php echo escape($row["identificador"]); ?></td>
<td class="cell"><?php echo escape($row["marca"]); ?></td>
<td class="cell"><?php echo escape($row["modelo"]); ?></td>
<td class="cell"><?php echo escape($row["matricula"]); ?></td>
<td class="cell"><button type="submit" name="submit"
value="<?php echo escape($row["identificador"]); ?>">Borrar</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
</div><!--//table-responsive-->
</div><!--//app-card-body-->
</div><!--//app-card-->
</div><!--//tab-pane-->
</div><!--//tab-content-->
</div><!--//container-fluid-->
</div><!--//app-content-->
<?php require './templates/footer.php';?>
<!-- Javascript -->
<script src="assets/plugins/popper.min.js"></script>
<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<!-- Page Specific JS -->
<script src="assets/js/app.js"></script>
</body>
</html>