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.
 
 
 
 
 
 

84 lines
2.4 KiB

<?php
/**
* Delete a user
*/
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 = "User successfully deleted";
} 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();
}
?>
<?php require "../templates/header.php"; ?>
<section id="five" class="main style1">
<div class="container">
<section>
<h2>Borrar vehículos</h2>
<?php if ($success) echo $success; ?>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<table>
<thead>
<tr>
<th>#</th>
<th>Marca</th>
<th>Modelo</th>
<th>Matrícula</th>
<th>Borrar</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["identificador"]); ?></td>
<td><?php echo escape($row["marca"]); ?></td>
<td><?php echo escape($row["modelo"]); ?></td>
<td><?php echo escape($row["matricula"]); ?></td>
<td><button type="submit" name="submit"
value="<?php echo escape($row["identificador"]); ?>">Borrar</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
</section>
</div>
</section>
<?php require "../templates/footer.php"; ?>