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.
 
 
 
 
 
 

88 lines
2.5 KiB

<?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 class="principal">
<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']); ?>">
<p><label for="marca">Marca</label></p>
<p><input type="text" id="marca" name="marca"></p>
<input type="submit" name="submit" value="Ver resultados" class="primary">
</div>
</form>
</section>
</div>
</section>
<?php require "../templates/footer.php"; ?>