Cómo transferir el número de código de barras en la base de datos mysql
Frecuentes
Visto 2,217 veces
1 Respuestas
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.
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 php jquery ajax or haz tu propia pregunta.
Yes, is called scripting and connecting to database and insert. Di you try anything? - Mihai Iorga
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