Cómo transferir el número de código de barras en la base de datos mysql

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

preguntado el 28 de agosto de 12 a las 08:08

Yes, is called scripting and connecting to database and insert. Di you try anything? -

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. -

1 Respuestas

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.

Aquí tienes un ejemplo para empezar.

enviar.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>

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

Respondido 28 ago 12, 09:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.