5
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by network18
0

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

-2

<html>
<head>

<title> Scan Outbound tapes to Iron Mountain Processing </title>
</head>
<body>
<!-- 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>

<?php
// 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');
mysql_select_db($dbname);
$sql = "INSERT INTO daily_outbound (serialnum) VALUES ('".$_POST."')";
mysql_query($sql) or die ('Error, insert query failed');
$snum = $_POST;
mysql_close($conn);
printf("Tape serial number %s was added to Tape database\n", $snum);
$snum = '';
exit();
?>
</form>
</body>
</html>

Edited by TCANIPE: n/a

0

Hey.

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 :)

0

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 -

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

<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);" />
</form>
</html>

- 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

Edited by network18: Edit:submit error due to large traffic

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.