简体   繁体   English

如何在mysql数据库上传输条形码编号

[英]How to transfer barcode number on mysql database

I want to send my product barcode number on my mysql database. 我想在我的mysql数据库上发送产品条形码编号。 When some one scan product barcode then automatically barcode number transfer on mysql database. 当有人扫描产品条形码时,条形码数据会自动在mysql数据库上传输。 There is any way to do this job. 有任何方法可以完成这项工作。 Thanks 谢谢

I believe the form is auto-submited when a barcode-reader reads a barcode. 我相信,当条形码阅读器读取条形码时,表格会自动提交。 So add the input last. 因此,最后添加输入。 Or catch the submit event with javascript and don't submit until you actually hit submit. 或者使用javascript捕获提交事件,直到您真正点击提交后再提交。

Here's an example to get you started. 这是一个入门的示例。

submit.php Submit.php

<html>
    <head>
        <title>Insert product</title>
    </head>
    <body>
        <form method="post" action="insert.php">
            Product: <input type="text" name="product" /><br />
            Barcode: <input type="text" name="barcode" /><br />
            <input type="submit" value="Insert barcode" />
        </form>
    </body>
</html>

insert.php insert.php

<?php
$db = new PDO('mysql:host=localhost;dbname=myDatabase', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false));

$barcode = $_POST['barcode'];
$product = $_POST['product'];

try {
    $db->beginTransaction();
    $stmt = $db->prepare("INSERT INTO `barcodes` (`barcode`, `product`) VALUES (:barcode, :product)");
    $stmt->execute(array(':barcode' => $barcode, ':product' => $product));
    $db->commit();
} catch(PDOException $ex) {
    $db->rollBack();
    echo $ex->getMessage();
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM