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
| <?php
//Connections
try {
$handler = new PDO('mysql:host=localhost:3307;dbname=base_barcode','login', 'password');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
exit($e->getMessage());
}
$codebar = isset($_GET['barcode']) ? $_GET['barcode'] : NULL;
//Verification
if(!isset($error)){
//no error
$sthandler = $handler->prepare("SELECT * FROM table2 WHERE quantity = 0 AND table2_Barcod=:barcode");
$sthandler->bindParam(':barcode', $codebar);
$sthandler->execute();
if($sthandler->rowCount() > 0 ){
echo "<center><span style=background:#FFFFFF><font color=red><b>!! Code déjà scanné !!</b></font></span><br />";
header("Refresh: 3; URL=indexphp");
} else {
//insert into database
$sql = 'insert into table2 (table2_Barcod, table2_Qty, table2_datetime, table2_process, table2_user, table2_zone)
SELECT distinct table1_Barcod, table1_Qty, now(), "C", "data1", "data2"
from table1
where table1_Barcod = :barcode';
$query = $handler->prepare($sql);
$query->execute(array(':barcode' => $codebar));
echo "<center><FONT SIZE=4 FACE=Arial><b><font color='red'>enregistrement en base...</font></font></center>";
echo "<center><FONT SIZE=20 FACE=Arial><b><font color='green'>OK</font></font></center>";
echo "<center><FONT SIZE=2 FACE=Arial><b>Redirection en cours...</font></center>";
header("Refresh: 3; URL=index.php");
}
}else{
echo "erreur d'insertion, réessayez ".$error;
exit();
}
?> |
Partager