0

I want to send my product barcode number on my mysql database. When some one scan product barcode then automatically barcode number transfer on mysql database. There is any way to do this job. Thanks

2
  • 2
    Yes, is called scripting and connecting to database and insert. Di you try anything? Aug 28, 2012 at 8:00
  • First you need a hardware to scan barcode. PHP can't directly communicate with hardware, so you need to take help of OCX, or Flash Component or any other executable file that can be called via php, then fetch the barcode number of the product and save it to database using normal php mysql operation.
    – WatsMyName
    Aug 28, 2012 at 8:10

1 Answer 1

0

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.

Here's an example to get you started.

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

<?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();
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.