<?php
|
|
|
|
/**
|
|
* Function to query information based on
|
|
* a parameter: in this case, marca.
|
|
*
|
|
*/
|
|
|
|
require "../../config.php";
|
|
require "../../common.php";
|
|
|
|
if (isset($_POST['submit'])) {
|
|
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
|
|
|
|
try {
|
|
$connection = new PDO($dsn, $username, $password, $options);
|
|
|
|
$sql = "SELECT *
|
|
FROM vehiculos
|
|
WHERE marca = :marca";
|
|
|
|
$marca = $_POST['marca'];
|
|
$statement = $connection->prepare($sql);
|
|
$statement->bindParam(':marca', $marca, PDO::PARAM_STR);
|
|
$statement->execute();
|
|
|
|
$result = $statement->fetchAll();
|
|
} catch(PDOException $error) {
|
|
echo $sql . "<br>" . $error->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<?php require "../templates/header.php"; ?>
|
|
|
|
<?php
|
|
if (isset($_POST['submit'])) {
|
|
if ($result && $statement->rowCount() > 0) { ?>
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<h2>Resultados</h2>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Marca</th>
|
|
<th>Modelo</th>
|
|
<th>Matrícula</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>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</section>
|
|
</div>
|
|
</section>
|
|
<?php } else { ?>
|
|
<blockquote>No results found for <?php echo escape($_POST['marca']); ?>.</blockquote>
|
|
<?php }
|
|
} ?>
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<h2>Busca vehículo por marca</h2>
|
|
|
|
<form method="post">
|
|
<div class="row gtr-uniform gtr-50">
|
|
|
|
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
|
|
<div class="col-12">
|
|
|
|
<label for="marca">Marca</label>
|
|
<input type="text" id="marca" name="marca">
|
|
</div>
|
|
<div class="col-12">
|
|
<input type="submit" name="submit" value="Ver resultados" class="primary">
|
|
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<a href="menu.php" class="button small">Volver</a>
|
|
</section>
|
|
</div>
|
|
</section>
|
|
<?php require "../templates/footer.php"; ?>
|