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.
 
 
 
 
 
 

102 lines
3.0 KiB

<?php
/**
* Use an HTML form to create a new entry in the
* users table.
*
*/
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);
$vehiculo =[
"identificador" => $_POST['identificador'],
"marca" => $_POST['marca'],
"modelo" => $_POST['modelo'],
"matricula" => $_POST['matricula']
];
$sql = "UPDATE vehiculos
SET identificador = :identificador,
marca = :marca,
modelo = :modelo,
matricula = :matricula
WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->execute($vehiculo);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
if (isset($_GET['identificador'])) {
try {
$connection = new PDO($dsn, $username, $password, $options);
$identificador = $_GET['identificador'];
$sql = "SELECT * FROM vehiculos WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->bindValue(':identificador', $identificador);
$statement->execute();
$vehiculo = $statement->fetch(PDO::FETCH_ASSOC);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
} else {
echo "¡Algo ha salido mal!";
exit;
}
?>
<?php require "./cabecera.php"; ?>
<?php if (isset($_POST['submit']) && $statement) : ?>
<blockquote><?php echo escape($_POST['marca']); ?> successfully updated.</blockquote>
<?php endif; ?>
<div class="app-wrapper">
<div class="container-xl">
<h1 class="app-page-title">Edita un vehículo</h1>
<hr class="mb-4">
<div class="app-card-body">
<form class="settings-form" method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<?php foreach ($vehiculo as $key => $value) : ?>
<div class="mb-3">
<label class="form-label" for="<?php echo $key; ?>"><?php echo ucfirst($key); ?></label>
<input class="form-control" type="text" name="<?php echo $key; ?>" identificador="<?php echo $key; ?>"
value="<?php echo escape($value); ?>" <?php echo ($key === 'identificador' ? 'readonly' : null); ?>>
</div>
<?php endforeach; ?>
<input type="submit" class="btn app-btn-primary" name="submit" value="Enviar">
</form>
</div>
</div>
</div>
<?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>