Skip to content

Instantly share code, notes, and snippets.

@krez69
Created October 16, 2019 11:47
Show Gist options
  • Save krez69/3faf3250ecabad51571aefa5efdb7c82 to your computer and use it in GitHub Desktop.
Save krez69/3faf3250ecabad51571aefa5efdb7c82 to your computer and use it in GitHub Desktop.
<?php
require_once 'connect.php';
$pdo = new \PDO (DSN, USER, PASS);
//Recuperer les élements du tableaux bribe
$query = "SELECT * FROM bribe";
$statement = $pdo->query($query);
$bribes = $statement->fetchAll(PDO::FETCH_ASSOC);
$name = $payment = "";
$errors = [];
//conditions d'erreurs
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST)) {
if (empty(trim($_POST["name"]))) {
$errors['name']= "name is required";
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/", $name)) {
$errors ['name']= "Only letters and white space allowed";
}
}
if ($_POST['payment'] <= 0){
$errors['payment'] = 'tu te fous de ma gueule';
}
if (empty($_POST["payment"])) {
$errors['payment']= "payment is required";
}
}
//INSERTION
if (!empty($_POST) && (empty($errors))){
$name = trim($_POST['name']);
$payment = $_POST['payment'];
$query = "INSERT INTO bribe (name, payment)
VALUES (:name, :payment)";
$statement = $pdo->prepare($query);
$statement->bindValue(':name', $name, \PDO::PARAM_STR);
$statement->bindValue(':payment', $payment, \PDO::PARAM_INT);
$statement->execute();
header('Location: book.php ');
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/book.css">
<title>Checkpoint PHP 1</title>
</head>
<body>
<?php include 'header.php'; ?>
<main class="container">
<section class="desktop">
<img src="image/whisky.png" alt="a whisky glass" class="whisky"/>
<img src="image/empty_whisky.png" alt="an empty whisky glass" class="empty-whisky"/>
<div class="pages">
<div class="page leftpage">
Add a bribe
<!-- TODO : Form -->
<form novalidate action="" method="post" class="sponsorship">
<div class="sponsorship_div">
<label for="name" class="parrainage">Name</label><br>
<input id="name" required type="text" name="name" class="mb-4 form-control">
<span class="error"><?php if (isset($errors['name'])){
echo $errors['name']; } ?></span>
</div>
<div>
<label for="payment" class="parrainage">Payment</label><br>
<input id="payment" required type="number" name="payment"
class="mb-4 form-control">
<span class="error"><?php if (isset($errors['payment'])){
echo $errors['payment']; } ?></span>
</div>
<input type="submit" value="Pay !" class="w-50 btn btn-success">
</form>
</div>
<div class="page rightpage">
<!-- TODO : Display bribes and total paiement -->
<h2 class="S"> S </h2>
<table style="width:100%">
<tr><?php
$sum = 0;
foreach ($bribes as $bribe) { ?>
<td><?= $bribe['name'] ?></td>
<td><?= $bribe['payment'] . "";
$sum += $bribe['payment'] ?></td>
</tr><?php } ?>
<tfoot>
<tr>
<td>Total</td>
<td><?php echo $sum . "";?></td>
</tr>
</tfoot>
</table>
</div>
</div>
<img src="image/inkpen.png" alt="an ink pen" class="inkpen"/>
</section>
</main>
</body>
</html>
@import url('https://fonts.googleapis.com/css?family=Bilbo+Swash+Caps&display=swap');
body {
background-image: url('../image/background.jpeg');
background-repeat: no-repeat;
background-size: cover;
}
main {
padding-top: 4em;
font-size: 26pt;
font-family: 'Bilbo Swash Caps', cursive;
}
.whisky, .empty-whisky, .inkpen, .page {
filter: drop-shadow(15px 15px 5px var(--shadow));
z-index: 2;
}
.inkpen{
margin:auto;
}
.whisky{
margin: auto;
padding-bottom: 900px;
}
.empty-whisky{
display: none;
}
.desktop{
display: flex;
justify-content: space-between;
}
.pages {
display: flex;
width: auto;
flex-basis : 65%;
margin:1em;
}
.page {
height:65vh;
padding: 3vw;
width: 50%;
background-blend-mode: multiply;
}
.leftpage {
background: url('../image/paper.png'), linear-gradient(270deg, rgba(157,158,137,1) 0%, rgba(233,226,187,1) 5%, rgba(255,251,203,1) 18%);
border-radius: 24px 40% 40% 24px/8px 8px 8px 8px;
}
.rightpage {
background: url('../image/paper.png'), linear-gradient(90deg, rgba(157,158,137,1) 0%, rgba(233,226,187,1) 5%, rgba(255,251,203,1) 18%);
border-radius: 40% 24px 24px 40%/8px 8px 8px 8px;
overflow: auto;
}
.S{
text-align: center;
border-bottom: solid 1px black;
margin: auto;
}
@media only screen and (max-width : 1200px){
/* Styles pour cette Media Queries */
.inkpen{
display: none;
}
}
@media only screen and (max-width : 1100px){
/* Styles pour cette Media Queries */
.whisky{
display: none;
}
.empty-whisky{
display: flex;
margin: auto;
padding-bottom: 900px;
}
}
@media only screen and (min-device-width : 800px) and (max-device-width : 1000px) {
/* Styles pour cette Media Queries */
.empty-whisky{
display: none;
}
.desktop{
display: block;
}
}
@media only screen and (max-width : 800px) {
/* Styles pour cette Media Queries */
.empty-whisky{
display: none;
}
.desktop{
display:block;
}
.pages{
flex-direction: column-reverse;
align-items: center;
}
.page{
width: 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment