1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| <?php
require_once('includes/bdd_connect.php');
$response=$bdd->query('SELECT * FROM comptebancaire');
$saisie=$response->fetchAll();
$response->closeCursor();
if(isset($_POST['dateoperation'], $_POST['operation'], $_POST['debit'], $_POST['credit'])
AND !empty($_POST['dateoperation'])
AND !empty($_POST['operation'])
AND !empty($_POST['debit'])
AND !empty($_POST['credit'])
){
if(!preg_match('#^[a-zA-ZáàâäãåçéèêëíìîïñóòôöõúùûüýÿæÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝÆ \-\']{2,25}$#i', $_POST['operation'])){
$errors[] = "Opération incorrecte";
}
if(!preg_match('#^[0-9]{1,20}([.,][0-9]{1,2})?$#', $_POST['debit'],$_POST['credit'])){
$errors[] = "Montant incorrect";
}
}
if(empty($saisie)){
$response =$bdd->prepare("INSERT INTO comptebancaire(dateoperation, operation, debit, credit) VALUES(?,?,?,?)");
$response->execute(array($_POST['dateoperation'],$_POST['operation'],$_POST['debit'],$_POST['credit']));
if($response->rowCount()>0){//Vérifie si l'opération a bien été ajouté dans la BDD
$successMsg = 'L\'opération a bien été ajoutée !';
}else{
$errorMsg[]='Suite à un problème dans la base de données, l\'opération n\'a pas pu être ajoutée !';
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/carousel.css">
<title>Compte bancaire</title>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<h1 style="font-size:25px;text-align:center;color:green;">Compte bancaire</h1>
<table>
<tr>
<th>Date</th>
<th>Opérations</th>
<th>Débit</th>
<th>Crédit</th>
<th>Solde</th>
</tr>
<?php
if(empty($saisie)){
echo'<span style="font-size:30px;color:red;"><span>';
} else{
foreach($saisie as $data){
echo'<tr><td>'.htmlspecialchars($data['dateoperation']).'</td><td>'.htmlspecialchars($data['operation']).'</td><td>'.htmlspecialchars($data['debit']).'</td><td>'.htmlspecialchars($data['credit']).'</td></tr>'.'</li>';
}
}
?>
<tr>
<form action="index.php" method="POST">
<input type="date" name="dateoperation" placeholder="" required>
<input type="text" name="operation" placeholder="" required>
<input type="text" name="debit" placeholder="" required>
<input type="text" name="credit" placeholder="" required>
<input type="submit" name="">
</form>
</tr>
</table>
<script type="application/javascript" src="js/jquery-3.1.1.js"></script>
<script src="js/script.js"></script>
</body>
</html> |
Partager