<?php
|
|
|
|
/**
|
|
* Use an HTML form to edit an entry in the
|
|
* vehiculos 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 "../templates/header.php"; ?>
|
|
|
|
<?php if (isset($_POST['submit']) && $statement) : ?>
|
|
<blockquote><?php echo escape($_POST['marca']); ?> successfully updated.</blockquote>
|
|
<?php endif; ?>
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<h2>Edita un vehículo</h2>
|
|
|
|
<form method="post">
|
|
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
|
|
<?php foreach ($vehiculo as $key => $value) : ?>
|
|
<label for="<?php echo $key; ?>"><?php echo ucfirst($key); ?></label>
|
|
<input type="text" name="<?php echo $key; ?>" identificador="<?php echo $key; ?>"
|
|
value="<?php echo escape($value); ?>" <?php echo ($key === 'identificador' ? 'readonly' : null); ?>>
|
|
<?php endforeach; ?>
|
|
<br>
|
|
<input type="submit" name="submit" class="primary" value="Submit">
|
|
</form>
|
|
|
|
<a href="menu.php" class="button small" >Volver</a>
|
|
</section>
|
|
</div>
|
|
</section>
|
|
<?php require "../templates/footer.php"; ?>
|