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 84 85 86 87 88 89 90
|
<?php
//Connexion bdd
try {
$handler = new PDO('mysql:host=localhost:3307;dbname=tests','root', '');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
exit($e->getMessage());
}
$codebar = isset($_POST['barcode']) ? $_POST['barcode'] : NULL;
//Verification
if(!isset($error)){
//check en base
$sthandler = $handler->prepare("SELECT * FROM table2 WHERE conso_UpdateQty = 0 AND conso_Barcod=:barcode");
$sthandler->bindParam(':barcode', $codebar);
$sthandler->execute();
if($sthandler->rowCount() > 0){
echo "<center><font color='black'><b>! Code déjà scanné ! </font><br />";
header("Refresh: 2; URL=urlretour.php");
} else {
//insert en base
$sql = 'insert into etc...';
$query = $handler->prepare($sql);
$query->execute(array(':barcode' => $codebar));
// si echo ici , il s'affiche directement dans la page
// echo "<center><font color='black'><b>! Code déjà scanné ! </font><br />";
}
}else{
echo "erreur d'insertion, réessayez ".$error;
exit();
}
?>
// Ensuite mon HTML du formulaire.
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="favicon.ico" />
<style>
@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,600,400italic);
html, body {
height: 100%;
margin: 0; padding: 0;
font-family: "Roboto", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 20px;
color: #777;
background: #ff0084; /* Old browsers */
background: -moz-linear-gradient(top, #ff0084 0%, #ff0084 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #ff0084 0%,#ff0084 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #ff0084 0%,#ff0084 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0084', endColorstr='#ff0084',GradientType=0 ); /* IE6-9 */
}
body {
display : table;
width: 100%;
}
footer {
display : table-row;
height: 100px;
font-size: 8px;
font-color: #FFF;
}
</style>
<title>TEST</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
</head>
<body>
<center>
<form action="monfichier.php" method="POST" class="pure-form pure-form-stacked">
<fieldset>
<label for="barcode"><font color="white">Scannez le code barre</font></label>
<input type="text" id="barcode" name="barcode" placeholder="Code barres" autofocus="focus"><br />
<button type="submit" name="insert" class="pure-button button-xlarge pure-button-primary">CONSOMMER</button>
</fieldset>
</form>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function() {$('[autofocus]').focus()});
</script>
</html> |
Partager