Hi Jason,

        Sorry but your code doesn't work. I tried fiddling with it but since
I'm a newbie, I'm a bit lost.


for lines that has '$isbn" -> should it read '$isbn'?

After submitting the form to itself, I tried to echo the $status, $newisdn
but nothing comes out. 

For The Javascript, can I ask you if it's possible for the focus to go from
Input1 to input2 consequtively? eg:

        |-------------|         |-----------------|     
        | ISBN Box        |             | SKU number    |  SUBMIT
        |-------------|         |-----------------|

Scan at 'ISBN Box', focus goes to 'SKU number' and then subsequently it
submits the data into the server.

Okay.. here's what I'm trying to prove.

I have a bunch of books, which I need to scan in the ISBN & the
corresponding SKU number and then submit it to mySQL.

@ 1st i was thinking I can just scan in the list of ISBN numbers and then go
to another box and scan in the SKU numbers and then input them into MySQL
together(but then I'll be opening up another can of worms to match ISBN to
SKU for each line!). If I do that, I won't be able to determine if there's
duplicate entries before I submit it.

John Holmes solution worked but needed a few tweaks for the \n and \r the
scanner puts in automatically.

If anyone can point me in the right direction, please help. 


Cheers,
Mun Heng, Ow
H/M Engineering
Western Digital M'sia 
DID : 03-7870 5168


-----Original Message-----
From: Jason Paschal [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 17, 2003 11:54 AM
To: Ow Mun Heng
Subject: Re: [PHP] Q : HELP HTML forms parsed into an array for PHP


from what i've experienced w/ bar code scanners, they send a carriage return

after inputting the numbers, so why not just have a page w/ a single input 
text field and a submit button that submits to itself? i threw in some 
javascript, also, that should set focus to the text field when the page 
loads, so if you are scanning in a bunch of items, you scan, it 
automatically submits, and is ready for the next one.
that's the idea, anyway, assuming your bar code scanner is setup to send a 
carriage return signal.

name of page is form.php:

<?php
$cn = mysql_connect("localhost","username","password");
$db = mysql_select_db("mydatabase");

if ($status=="newisbn") {
  $isbn= trim($isbn);
  $sql = "select * from table where isbn = '$isbn";
  $q = mysq_query($sql);
  $nr = mysql_num_rows($q);
  if ($nr < 1) {
     $sql = "insert into table (isbn) values ('$isbn)";
     $q = mysql_query($sql);
     echo "Successful insert.<br>";
  } else {
     echo "ISBN already exists.  $newisbn<br>";
  }
}
?>

<html>
<body onLoad="document.getElementById('isbn').focus()">
<form name="myform" method="post" action="form.php">
Input:<input type="text" id="isbn" name="isbn">
<input type="hidden" name="status" value="newisbn">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

-----Original Message-----
From: John W. Holmes [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 17, 2003 10:34 AM
To: Ow Mun Heng
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Q : HELP HTML forms parsed into an array for PHP

$isbn_string = "('" . str_replace("\n","'),\n('",$_POST['isbn']) . "')";
$query = "INSERT INTO table VALUES $isbn_string";

-- 
---John Holmes...

>From: "Ow Mun Heng" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Subject: [PHP] Q : HELP HTML forms parsed into an array for PHP
>Date: Tue, 17 Jun 2003 10:27:46 +0800
>
>Hi all,
>
>       Really hope someone can help me out.
>
>What I would like to do is to input multiple isbn numbers into a form, get
>PHP to parse it into an array so that I can build the SQL query for 
>multiple
>insert. Currently I'm able to perform single inputs, one at a time, which 
>is
>time consuming.
>
>I want to have a form<textarea name=isbn row=10 col=13> set up to get user
>input (multiline, each line separated by a carriage return - actually it's
>barcode is scanned in)
>       eg : ISBN - 1-111-22222-1
>                       1-111-22222-2
>                       1-111-22222-3
>
>I would like to parse this data into PHP and get PHP to use a foreach loop
>(or a for loop) so that I can build up the $query to form ('isbn1')
>('isbn2') ('isbn3').
>
>I'm trying to insert into mySQL a multiple value insert sort of like
>
>$query =       insert into table values
>               ('isbn1')
>               ('isbn2')
>               ('isbn3');
>
>
>Cheers,
>Mun Heng, Ow
>H/M Engineering
>Western Digital M'sia
>DID : 03-7870 5168
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to