Hi all, anyone have idea how to setup a barcode reader within virtuemart ?

Recommended Answers

All 4 Replies

to read from a users computer and upload it to the server ?
because that i dont think is possible with php alone but i could be wrong


<title> Scan Outbound tapes to Iron Mountain Processing </title>
<!-- Original Code
<form action="insert2outbound.php" method="POST"> -->

<!-- New Code: -->

<form method="POST"
<p>Scan / Enter Tape's serial number: <br>
<p><input type="text" name="serialnum" size="100"></p>
<!-- <p><input type="submit" name="submit" value="Insert Record"></p> -->
<p><input type="submit" name="quit" value="Exit"></p>

// Connect to server and select database
$dbhost = 'server1';
$dbuser = 'poser';
$dbpasswd = 'monkey';
$dbname = 'torpedo';
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd) or die ('Error connectiong to mysql');
$sql = "INSERT INTO daily_outbound (serialnum) VALUES ('".$_POST."')";
mysql_query($sql) or die ('Error, insert query failed');
$snum = $_POST;
printf("Tape serial number %s was added to Tape database\n", $snum);
$snum = '';


No offense, TCANIPE, but that code is just... bad.

Let me explain:

  1. Most importantly, you NEVER put a $_POST variable (or any variable, for that matter) into a MySQL query without running it through mysql_real_escape_query, or something equivalent. It leaves you wide open for SQL Injection.
  2. The way your PHP code is set up there, it will insert a row every time the page is shown, regardless of whether there is any data to insert. Which leaves you with a table full of empty serialnum values.
  3. Your PHP code does an exit , which cuts the page off before the end of the HTML is shown.
  4. The <form> element isn't complete. You just left it open and missing the action attribute.
  5. Your submit button is labeled "Exit". (The one labeled "Insert record" is commented out ;P)

I don't mean to sound offensive tho. Just couldn't leave it untold.

How exactly does this relate to the OP's question anyways?

To the OP.
Sorry, I'm afraid I won't be of much use to you. I have no idea what virtuemart is, and I was never any good at dealing with hardware :)

A barcode is a graphical representation of string. All barcode readers take this graphic SCAN and convert it into a String for the computer to understand.Most automatically input it into the computer as the string had been typed on the keyboard. Additionally, most scanners come with the default set to append an ENTER or RETURN to the end of each barcode scanned. The process involves -
- Create an Form like <Input type=text name=barcode size=x>
- use Javascript to ensure focus on your "barcode" field, something like -

<script language="javascript">
function setFocus(){document.myForm.inputTextBox.focus();}
// -->

<body onLoad=setFocus()>
<form name="myForm" action="form.php" method="post">
<input name="inputTextBox" type="text">
<input name="submit" type="submit">

<input type="text" name="itm_barcode" maxlength="16" tabindex="1" onChange="javascript:submit();" onkeypress="return handleEnter(this, event);" />

- when a user scans a barcode the form will automatically be submitted provided that the barcode scanner is appending a RETURN or ENTER key
and then do whatever with it, like you can enter it into the database.
or else have a look here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.