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.
 
 
 
 
 
 

90 lines
2.8 KiB

<?php
/**
* Use an HTML form to edit an entry in the
* kmss 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);
$kms =[
"identificador" => $_POST['identificador'],
"fecha" => $_POST['fecha'],
"kms" => $_POST['kms'],
"litros" => str_replace(',', '.',$_POST['litros']),
"descuento" => str_replace(',', '.',$_POST['descuento']),
"precioxlitro" => str_replace(',', '.',$_POST['precioxlitro']),
"importe" => str_replace(',', '.',$_POST['importe'])
];
$sql = "UPDATE carburante
SET identificador = :identificador,
fecha = :fecha,
kms = :kms,
litros = :litros,
descuento = :descuento,
precioxlitro = :precioxlitro,
importe = :importe
WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->execute($kms);
} 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 carburante WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->bindValue(':identificador', $identificador);
$statement->execute();
$kms = $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['fecha']); ?> successfully updated.</blockquote>
<?php endif; ?>
<section id="five" class="main style1">
<div class="container">
<section>
<h2>Edita un repostaje</h2>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<?php foreach ($kms 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; ?>
<input type="submit" name="submit" value="Submit">
</form>
</section>
<a href="menu.php" class="button small">Volver</a>
</div>
</section>
<?php require "../templates/footer.php"; ?>