<?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);
|
|
|
|
$nuevo_coche = array(
|
|
"marca" => $_POST['marca'],
|
|
"modelo" => $_POST['modelo'],
|
|
"matricula" => $_POST['matricula']
|
|
);
|
|
|
|
$sql = sprintf(
|
|
"INSERT INTO %s (%s) values (%s)",
|
|
"vehiculos",
|
|
implode(", ", array_keys($nuevo_coche)),
|
|
":" . implode(", :", array_keys($nuevo_coche))
|
|
);
|
|
|
|
$statement = $connection->prepare($sql);
|
|
$statement->execute($nuevo_coche);
|
|
} catch(PDOException $error) {
|
|
echo $sql . "<br>" . $error->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<?php require "../templates/header.php"; ?>
|
|
|
|
<?php if (isset($_POST['submit']) && $statement) : ?>
|
|
<blockquote><?php echo escape($_POST['marca']); ?> successfully added.</blockquote>
|
|
<?php endif; ?>
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<h2>Añadir vehículo</h2>
|
|
|
|
<form method="post">
|
|
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
|
|
<label for="marca">Marca</label>
|
|
<input type="text" name="marca" id="marca">
|
|
<label for="modelo">Modelo</label>
|
|
<input type="text" name="modelo" id="modelo">
|
|
<label for="matricula">Matricula</label>
|
|
<input type="text" name="matricula" id="matricula">
|
|
<br>
|
|
<input type="submit" name="submit" value="Crear" class="primary">
|
|
</form>
|
|
<a href="menu.php" class="button small">Volver</a>
|
|
|
|
</section>
|
|
</div>
|
|
</section>
|
|
|
|
<?php require "../templates/footer.php"; ?>
|