Barcode scanners in PHP applications

Published on 27.02.2012, by Lubos Dzurik

Barcode scanners in PHP applications

PHP can be easily utilized for reading bar codes printed on paper documents. Connecting manual barcode reader to the computer via USB significantly extends usability of PHP (or any other web programming language) into tasks involving document and product management, like finding a book records in the database or listing all bills for a particular customer.

Following sections briefly describe process of connecting and using manual bar code reader with PHP.

The usage of bar code scanners described in this article are in the same way applicable to any web programming language, such as ASP, Python or Perl. This article uses only PHP since all tests have been done with PHP applications.

What is a bar code reader (scanner)

Bar code reader is a hardware pluggable into computer that sends decoded bar code strings into computer. The trick is to know how to catch that received string. With PHP (and any other web programming language) the string will be placed into focused input HTML element in browser. Thus to catch received bar code string, following must be done:

  • just before reading the bar code, proper input element, such as INPUT TEXT FIELD must be focused (mouse cursor is inside of the input field).
  • once focused, start reading the code
  • when the code is recognized (bar code reader usually shortly beeps), it is send to the focused input field. By default, most of bar code readers will append extra special character to decoded bar code string called CRLF (ENTER). For example, if decoded bar code is "12345AB", then computer will receive "12345AB<ENTER>". Appended character <ENTER> (or <CRLF>) emulates pressing the key ENTER causing instant submission of the HTML form:
	

Choosing the right bar code scanner

When choosing bar code reader, one should consider what types of bar codes will be read with it. Some bar codes allow only numbers, others will not have checksum, some bar codes are difficult to print with inkjet printers, some barcode readers have narrow reading pane and cannot read for example barcodes with length over 10 cm. Most of barcode readers support common barcodes, such as EAN8, EAN13, CODE 39, Interleaved 2/5, Code 128 etc.

For office purposes, the most suitable barcodes seem to be those supporting full range of alphanumeric characters, which might be:

  • code 39 - supports 0-9, uppercased A-Z, and few special characters (dash, comma, space, $, /, +, %, *)
  • code 128 - supports 0-9, a-z, A-Z and other extended characters

Other important things to note:

  • make sure all standard barcodes are supported, at least CODE39, CODE128, Interleaved25, EAN8, EAN13, PDF417, QRCODE.
  • use only standard USB plugin cables. RS232 interfaces are meant for industrial usage, rather than connecting to single PC.
  • the cable should be long enough, at least 1.5 m - the longer the better.
  • bar code reader plugged into computer should not require other power supply - it should power up simply by connecting to PC via USB.
  • if you also need to print bar code into generated PDF documents, you can use TCPDF open source library that supports most of common 2D bar codes.

Installing scanner drivers

Installing manual bar code reader requires installing drivers for your particular operating system and should be normally supplied with purchased bar code reader.

Once installed and ready, bar code reader turns on signal LED light. Reading the barcode starts with pressing button for reading.

Scanning the barcode - how does it work?

STEP 1 - Focused input field ready for receiving character stream from bar code scanner:

STEP 2 - Received barcode string from bar code scanner is immediatelly submitted for search into database, which creates nice "automated" effect:

STEP 3 - Results returned after searching the database with submitted bar code:

Conclusion

It seems, that utilization of PHP (and actually any web programming language) for scanning the bar codes has been quite overlooked so far. However, with natural support of emulated keypress (ENTER/CRLF) it is very easy to automate collecting & processing recognized bar code strings via simple HTML (GUI) fomular.

The key is to understand, that recognized bar code string is instantly sent to the focused HTML element, such as INPUT text field with appended trailing character ASCII 13 (=ENTER/CRLF, configurable option), which instantly sends input text field with populated received barcode as a HTML formular to any other script for further processing.

Download links:


Comments...

pirs AT leosys DOT in

25.01.2013 10:11
# 1 Reply to pirs AT leosys DOT in    
 

but where is php code that actually reads the bar code; any download links? please suggest

lubosdz

25.01.2013 17:20
# 2 Reply to lubosdz    
 

pirs@leosys.in wrote on 25.01.2013 10:11:
but where is php code that actually reads the bar code; any download links? please suggest
Hi,

that's the point - you DONT need any special software for reading the bar codes! It is really easy to use it. The bar code would be decoded by hardware scanner and sent as sequence of characters (STRING) to currently focused element (e.g. on the webpage, MS Word, or cell in the Excel worksheet).

In the example above - you will just set cursor into input field and then read barcode - once the barcode is scanned and converted into STRING, it will appear in focused field. Usually, STRING has attached also the ENTER character at the end, so it looks like you also pressed the ENTER key (this will cause submitting the web formular or inserting new line in MS Word).

Cheers.

Damien

07.02.2013 11:51
# 3 Reply to Damien    
 

Thanks, that is a very simple and extremely helpful explanation and one will certainly be making use of.

runny DOT gupta73 AT gmail DOT com

08.02.2013 17:46
# 4 Reply to runny DOT gupta73 AT gmail DOT com    
 

But i doubt...have you all tested it with an scanner...??

lubosdz

17.02.2013 22:26
# 5 Reply to lubosdz    
 

runny.gupta73@gmail.com wrote on 08.02.2013 17:46:
But i doubt...have you all tested it with an scanner...??
I have bought scanner CipherLab 1000 and tested how it works - the principle is the same for any standard manual barcode scanner.

Udara

18.03.2013 18:31
# 6 Reply to Udara    
 

Nice article, I got many information regarding the Barcode readers and barcoding. Now I knew how its works. I have another thing to know...As you mentioned there are various types of barcode scanners according to standard supports. Therefore how can know, which barcode scanner will be matched with my requirement ? And what should I consider before buy a barcode scanner ?

lubosdz

25.03.2013 00:07
# 7 Reply to lubosdz    
 

Udara wrote on 18.03.2013 18:31:
Nice article, I got many information regarding the Barcode readers and barcoding. Now I knew how its works. I have another thing to know...As you mentioned there are various types of barcode scanners according to standard supports. Therefore how can know, which barcode scanner will be matched with my requirement ? And what should I consider before buy a barcode scanner ?
Hi,
it all depends on the purpose of your application. For example:

- if you are going to write web application for managing stock goods or logistics, then make sure your barcode scanner supports EAN8, EAN13 - which are very commonly used in logistics.

- if you are writing web application for quick search of the supplier for particular goods, then you may want use QRCode.

- as for the office use or banking, it might be barcodes that combine numbers and alpha characters, like C39 (Code 39), C93, C128 or I25 (Interleaved 2/5).

- if you need to search international database of products, then you will probably need scanner that recognizes UPC code (Universal Product Code).

So there is no universal answer to your question. However, good news is, that most of barcode scanners today (even most basic models) support few tens of barcodes. So it is very likely, that whatever barcode you need, it will be supported. What matters more when choosing a bar code scanner, is the ability to read - better scanners can read more damaged barcodes or from longer distance. Dont hesitate to spend few bucks more on better scanner.

As a programmer - just bear in mind that whatever barcode you need to work with, you DONT NEED to write any application deciphering e.g. binary streams into barcode. All that happens on hardware side - you as a programmer always work with decipered barcode characters that are sent into your web application directly from scanner.

Read more about barcodes: http://en.wikipedia.org/wiki/Barcode

perastikos

11.04.2013 22:18
# 8 Reply to perastikos    
 

hello thanks for the article, my question is how can i filter the <enter> character so my input field will be clean barcode scanner?

thanks

lubosdz

11.04.2013 22:27
# 9 Reply to lubosdz    
 

perastikos wrote on 11.04.2013 22:18:
hello thanks for the article, my question is how can i filter the <enter> character so my input field will be clean barcode scanner?

thanks
Hi,
your focused input field will receive deciphered string, e.g. 654800AB69. You can configure your scanner (in scanner driver options) whether the <ENTER> character should be also attached to the string. Most scanner have pre-configured TRUE - so if you dont want it just set it to FALSE.

Julien

18.04.2013 15:52
# 10 Reply to Julien    
 

perastikos wrote on 11.04.2013 22:18:
hello thanks for the article, my question is how can i filter the <enter> character so my input field will be clean barcode scanner?

thanks
or you can just disable the form with
Code:
onsubmit='return false;'
so that your form will not be posted

perastikos

18.04.2013 23:47
# 11 Reply to perastikos    
 

@lubosdz if i dont find scanner options what else can i do?

@Julien i cant set submit form to false cause i want user to submit form and make some things, so its necessary for me

so maybe i have to filter string in my textbox and then proceed form

skondgekar AT yahoo DOT co DOT in

26.05.2013 05:15
# 12 Reply to skondgekar AT yahoo DOT co DOT in    
 

Hi I am going to make a project there is a need to use barcode scanner in Linux environment. Is there any drivers available in linux to configure barcode scanner

Rafique

03.07.2013 08:55
# 13 Reply to Rafique    
 

Hey Bro!! Thanks alot!! such an useful article!! helped me alot.. Thank you!!

Aitazaz khan

17.07.2013 10:16
# 14 Reply to Aitazaz khan    
 

Bro that's really work .you show it quite easy i love this blog and i am really thank full to you for this work thanks alot

abdulnaeemturk AT yahoo DOT com

17.07.2013 10:18
# 15 Reply to abdulnaeemturk AT yahoo DOT com    
 

Thanks i got too much idea from this and this article really helped to do this so on.
thanks once again for this article which helped me and it works

lubosdz

17.07.2013 21:23
# 16 Reply to lubosdz    
 

skondgekar@yahoo.co.in wrote on 26.05.2013 05:15:
Hi I am going to make a project there is a need to use barcode scanner in Linux environment. Is there any drivers available in linux to configure barcode scanner
It depends on the scanner manufacturer. Before you buy it, check what drivers does manufacturer offer downloading. Most of scanners have drivers supplied in the box.

In my case (CipherLab scanner CP210x) I found that linux drivers were supplied on mini CD that I bought along with the scanner. It was as *.RPM package for linux core 2.6+. Also separate manuals for linux/windows installation were supplied.

lubosdz

17.07.2013 21:26
# 17 Reply to lubosdz    
 

perastikos wrote on 18.04.2013 23:47:
@lubosdz if i dont find scanner options what else can i do?

@Julien i cant set submit form to false cause i want user to submit form and make some things, so its necessary for me

so maybe i have to filter string in my textbox and then proceed form
Buy another more standard scanner: -) This is very basic configurable option.

w DOT sahanyasiru AT yahoo DOT com

24.07.2013 06:23
# 18 Reply to w DOT sahanyasiru AT yahoo DOT com    
 

Very useful article. Thank you very much for sharing your knowledge. Please share article on barcode printing if you know about it. TX

lubosdz

24.07.2013 09:47
# 19 Reply to lubosdz    
 

w.sahanyasiru@yahoo.com wrote on 24.07.2013 06:23:
Very useful article. Thank you very much for sharing your knowledge. Please share article on barcode printing if you know about it. TX
Bar codes can be printed into PDF documents with PHP by few PDF manipulation libraries. For testing my barcode scanner above I used TCPDF library, which has nice support for most of 1D, 2D and QR bar codes. Check examples at http://www.tcpdf.org/examples.php.

w DOT sahanyasiru AT yahoo DOT com

24.07.2013 10:33
# 20 Reply to w DOT sahanyasiru AT yahoo DOT com    
 

Hi.
Thanks for your great support. I have already tried TCPDF library. Generate barcodes are ok. But I have a problem in printing those generated barcode. How to output barcodes to barcode printer. I don’t have any idea about barcode printers and how set printer alignments in TCPDF. If you know something please help me. TX.

bm_numan AT yahoo DOT com

13.09.2013 21:27
# 21 Reply to bm_numan AT yahoo DOT com    
 

Thanx. Very good article!

aremsajos83 AT gmail DOT com

13.01.2014 10:50
# 22 Reply to aremsajos83 AT gmail DOT com    
 

What abt the PHP code for the reader. Nobody ever mentioned the phph code am on that project. Please if υ̲̣̥ can be of help. Mail me @ aremsajos83@gmail.com

shoreas AT gmail DOT com

13.01.2014 18:04
# 23 Reply to shoreas AT gmail DOT com    
 

Re "... hardware pluggable into computer that ..."

Noob's question: Where/what do I plug the barcode reader into? USB port, or ???

I'm OK with the software side of things here - bigtime THANKS! - but new to barcode hardware stuff.

lubosdz

13.01.2014 21:43
# 24 Reply to lubosdz    
 

shoreas@gmail.com wrote on 13.01.2014 18:04:
Re "... hardware pluggable into computer that ..."

Noob's question: Where/what do I plug the barcode reader into? USB port, or ???

I'm OK with the software side of things here - bigtime THANKS! - but new to barcode hardware stuff.
Hi,
most of standard scanners are plugged via standard USB port (USB 1 or USB2). All such a scanners can be plugged Plug'n'Play into standard PC's USB port. Very few scanners use obscure RS232. Before buying, check with the manual from manufacturer, or just google up some picture of wanted model and see if there is USB cable.

lubosdz

13.01.2014 21:56
# 25 Reply to lubosdz    
 

aremsajos83@gmail.com wrote on 13.01.2014 10:50:
What abt the PHP code for the reader. Nobody ever mentioned the phph code am on that project. Please if υ̲̣̥ can be of help. Mail me @ aremsajos83@gmail.com

You dont need any PHP code for barcode scanner. Not in the way that interacts directly with the scanner. I understand your point, coz it was also a bit confising to me:-) But scanner is actually a standalone selfcontained piece of hardware that behaves in the same way just like e.g. keyboard: once it receives input, it sends it to some destination.

Example: if you are on HTML page inside of HTML form, pressing ENTER would submit the form. In the same way - once a scanner reads succesfully the barcode, it sends scanned string to current output. If you are right at the moment on the web page focusing some input text field, these submitted characters will appear in that field, and the form will be submitted to the server (because scanner by default appends character 13 = ENTER at the end of the submitted string). Then you can process this submitted form on server in an usual way - read the submitted barcode characters from the form field (usually $_POST global field) and process it.

mgkpro AT live DOT de

11.02.2014 12:14
# 26 Reply to mgkpro AT live DOT de    
 

Hi,
so far, so good.
But how could you process the submitted barcode (not just read --> process)?
Example: the barcode reader reads 123456AB, puts it into a text field, enter submitts automatically. How could I process the data submitted?
Back to exanple: Another form puts 123 into a field, searches string, finds 123=manufacturer #, 456=material code, AB=pieces and puts all according partial strings found in different fields?

Any ideas?

PS: Good blog

lubosdz

11.02.2014 21:23
# 27 Reply to lubosdz    
 

mgkpro@live.de wrote on 11.02.2014 12:14:
Hi,
so far, so good.
But how could you process the submitted barcode (not just read --> process)?
Example: the barcode reader reads 123456AB, puts it into a text field, enter submitts automatically. How could I process the data submitted?
Back to exanple: Another form puts 123 into a field, searches string, finds 123=manufacturer #, 456=material code, AB=pieces and puts all according partial strings found in different fields?

Any ideas?

PS: Good blog
Hi,

as I explained in comments above, on server you will find submitted string in global POST array (depending on submit method). Then you can do anything like so:
Code:
$myCode = $_POST['fieldNameWithMyCode']; $document = $database->findByBarCode($myCode); if($document){ // found document in the database, return all information e.g. title, category, .. return $document->title; }else{ // barcode has no corresponding record in the database return false; }

lubosdz

11.02.2014 21:25
# 28 Reply to lubosdz    
 

Also note, it is technically impossible to submit code from barcode scanner into multiple fields at the same time - it is ALWAYS just one field that can be handled.

andola DOT gayadhar AT gmail DOT com

12.03.2014 06:13
# 30 Reply to andola DOT gayadhar AT gmail DOT com    
 

I found this article very much helpful. But am having one question. My barcode scanner scans the code into my selected text box but not able to auto submit the form.
I am using Symbol USB barcode scanner(Motorola).
Thank you : )

lubosdz

12.03.2014 21:28
# 31 Reply to lubosdz    
 

andola.gayadhar@gmail.com wrote on 12.03.2014 06:13:
I found this article very much helpful. But am having one question. My barcode scanner scans the code into my selected text box but not able to auto submit the form.
I am using Symbol USB barcode scanner(Motorola).
Thank you : )
Most likely you need to configure your scanner driver to append EOL character to the end of submitted string. In most drivers, this is configurable option that is set by default to YES (= append EOL/ENTER character). You have it probably set to NO.

Another possibility is, that you have not embedded receiving focus field inside of HTML form. If you want to do automatic submission you MUST place the field inside of HTML form - otherwise pressing ENTER will not submit anything.

Eventually, instead of HTML form you may use javascript JQuery listener - check the link above for "jQuery plugin - barcode listener".

andola DOT gayadhar AT gmail DOT com

13.03.2014 07:06
# 32 Reply to andola DOT gayadhar AT gmail DOT com    
 

Got your point and since this scanner is a USB Scanner no driver nothing needs to be installed its just work like a plugin and play. Also i have made the HTML form to auto submit this.
My barcode reader scans each individual like its typed in keyboard. I am able to manage that but the problem is not able differentiate the keyboard chars and Scanned chars . As because in case of human typed chars he needs to press enter to search and in case of scanner will auto submit the form with keypress event.
Please have a look at the sample code.

Code:
$('#barcode').on('keypress',function(e){ if(timeinterval!=null){ clearTimeout(timeinterval); } timeinterval = setTimeout("details()",500) console.log(e.which);// IT types all the charcode of each individual scanned item });

Ahmet

19.03.2014 12:56
# 33 Reply to Ahmet    
 

Thank you for this article. I've been working on barcodes and it's very usefull to collect them.

Kolly

30.04.2014 10:09
# 34 Reply to Kolly    
 

Thank you very much for this article. More grease to your elbow

kartikeyan AT mindprosoft DOT com

21.08.2014 15:43
# 35 Reply to kartikeyan AT mindprosoft DOT com    
 

Hello All,

I studied your article it's too good, and i have one doubt here

1.shall i use WIFI bar code reader here
2.for example my file is in live, i have one PC but 2 guys want to scan the bar code through bar code reader, and that particular bar code value want to update in my database, so finally my question is it's possible to connect more then one bar code reader into one system as well as simultaneously my 2 guys want to scan the bar code and both of them want to insert the value in database with out any interference(it means finally i want to get each user bar code value count it's inserted in database)

lubosdz

21.08.2014 22:20
# 36 Reply to lubosdz    
 

kartikeyan@mindprosoft.com wrote on 21.08.2014 15:43:
Hello All,

I studied your article it's too good, and i have one doubt here

1.shall i use WIFI bar code reader here
2.for example my file is in live, i have one PC but 2 guys want to scan the bar code through bar code reader, and that particular bar code value want to update in my database, so finally my question is it's possible to connect more then one bar code reader into one system as well as simultaneously my 2 guys want to scan the bar code and both of them want to insert the value in database with out any interference(it means finally i want to get each user bar code value count it's inserted in database)

I understand, that you want to count the number of scanned barcodes from two people connected by a single computer. While it is perfectly possible to connect two (or three, four, depends how many USB slots are available) USB barcode scanners into a single computer, it might be a challenge to distinguish which person has sent which barcode.

In order to distinguish which person has scanned which barcode, you need to ensure, that each person will focus into his own input field assigned only for that person. You cannot distinguish by scanned barcodes (unless you programmatically change somehow driver settings for each device individually - but I never tried that and I would not recommend it).

So, the challenge is, how to guarantee focusing into correct input field ... you could use two pages open in a single browser but if barcodes are coming paralelly at the same time ... you need something to tell the browser "now switch to page 1 or page 2" ... this is really a challenge. I can think of only one possible solution right now - using individual computer per each barcode scanner while each computer would connect to the same backend database. If you have any better idea, let me know ...

arifiqbal AT outlook DOT com

04.10.2014 19:04
# 37 Reply to arifiqbal AT outlook DOT com    
 

Hello.. It's Helpful Article for Me. Thanks For Sharing.

shiju AT adequtellc DOT com

08.10.2014 13:23
# 38 Reply to shiju AT adequtellc DOT com    
 

Is it working ?

Shakthi

10.04.2015 21:15
# 39 Reply to Shakthi    
 

It is a very good article. Thank you so for much for sharing your knowledge.

nudgeeb AT gmail DOT com

21.05.2015 09:16
# 40 Reply to nudgeeb AT gmail DOT com    
 

My PHP code is accessed through mobile browsers which have apps and default camera functions to scan barcodes. I need to allow the "scan" button to trigger the default barcode reader and then copy the scanned numerics in a text field within the webpage. Any suggestions will be appreciated, the phones will run Windows 8.1

Anomy

21.08.2015 03:50
# 41 Reply to Anomy    
 

where is the code for the javascript functions this.focus() ?

lubosdz

22.08.2015 01:20
# 42 Reply to lubosdz    
 

Anomy wrote on 21.08.2015 03:50:
where is the code for the javascript functions this.focus() ?
It meant to be somewhere inside the HTML formular or on page load, e.g.:
Code:
<body onload="$('#barcode').focus();"> <form onmouseover="$('#barcode').focus();"> <input id="barcode" type="text"> </form> </body>

nt DOT ishanipatel AT gmail DOT com

27.11.2015 08:15
# 43 Reply to nt DOT ishanipatel AT gmail DOT com    
 

Hi ,
Does this code will work for retina scanner integration?
i want retina scanned image once scanner will scan my retina.

Thanks!
Ishani

dinshithn123 AT gmail DOT com

07.12.2015 07:54
# 44 Reply to dinshithn123 AT gmail DOT com    
 

thanks for the article, i want to know that what is search.php means in above code you provide?

lubosdz

07.12.2015 21:24
# 45 Reply to lubosdz    
 

nt.ishanipatel@gmail.com wrote on 27.11.2015 08:15:
Hi ,
Does this code will work for retina scanner integration?
i want retina scanned image once scanner will scan my retina.

Thanks!
Ishani
This is not about retina- / non-retina displays.
I explained in general how barcode scanners in general can work with PHP code - implementation principles. So if your "retina display" can show normal HTML formular, then "yes" - it will work :- )

lubosdz

07.12.2015 21:28
# 46 Reply to lubosdz    
 

dinshithn123@gmail.com wrote on 07.12.2015 07:54:
thanks for the article, i want to know that what is search.php means in above code you provide?
The search.php is a PHP script on server, to which is the HTML form submitted. Please see example how HTML formulars work, e.g. http://www.w3schools.com/php/php_forms.asp.

Kasuni Sri Lanka

28.04.2016 12:30
# 47 Reply to Kasuni Sri Lanka    
 

Sir, I am new to barcodes. I do not know anything about barcodes printing and types of barcodes and their standards. I understand your article 100% and have PHP knowledge. Assuming, I have a barcode scanner purchased, having correct code/html with form to catch the string from the scanner, (I want to have my barcode experience for the first time). Can I scan a barcode on a book or any other on a food item package or anything, using my barcode scanner and take that string to the text field on my webpage?
Thanks lot for sharing your knowledge.

lubosdz

28.04.2016 21:30
# 48 Reply to lubosdz    
 

Kasuni Sri Lanka wrote on 28.04.2016 12:30:
Sir, I am new to barcodes. I do not know anything about barcodes printing and types of barcodes and their standards. I understand your article 100% and have PHP knowledge. Assuming, I have a barcode scanner purchased, having correct code/html with form to catch the string from the scanner, (I want to have my barcode experience for the first time). Can I scan a barcode on a book or any other on a food item package or anything, using my barcode scanner and take that string to the text field on my webpage?
Thanks lot for sharing your knowledge.
Yes sir, you can scan any barcode in a book or a food package. It will always send deciphered string sequence into your HTML form (focused input field).

vaghelac AT gmail DOT com

22.07.2016 16:43
# 49 Reply to vaghelac AT gmail DOT com    
 

Hello Mans,

Yes
I have task perform on my php web application.
above user "lubosdz" put comment.
i have purchased bar-coded scanner.
but i dont'n how can i configure in my web app.
please help for my situation.

Thanks & Regards
Chirag Vaghela

ratnam

07.11.2016 12:42
# 50 Reply to ratnam    
 

I have a barcode scanner with multiple scanned data.
Is it possible to download the multiple scanning info into one text file / Data base
using php / mysql.

Mauricio G

10.11.2016 17:00
# 51 Reply to Mauricio G    
 

<script type="text/javascript">
fuction nameFuction(barcode){
//do it what ever!!!
}
</script>
<input id="barcode" type="text" onchange="nameFuction(this.value);">

Chinthika Rathnayake chinthika DOT jayani AT gmail DOT com

17.12.2016 19:57
# 52 Reply to Chinthika Rathnayake chinthika DOT jayani AT gmail DOT com    
 

sir,I have coded to get the scanned barcode from barcode reader in to a php code in PC. I want to know how can i insert the number pattern of the barcode into the php code as a text.Above is my php code.i need to assign the number patter in to the barcode_value variable.please help me with this.
<?php
date_default_timezone_set('Asia/Colombo');

$date=date("Y-m-d");

$barcode_value = '001002003789456';

$db=mysql_connect("localhost", "root", "") or die("Problem in connecting to mysql server.....");



mysql_select_db("post_office_mailing_system",$db) or die("Problem in connecting to database.....");


$sql = "SELECT count(*) as count_val FROM `letter_count` WHERE Barcode='$barcode_value' and Date ='$date'";




$result=mysql_query($sql) or die("Problem in query.....");

$value= mysql_fetch_assoc($result);


if($value != 0)
{
$sql2 = "update `letter_count` set Letter_count = Letter_count + 1 WHERE Barcode='$barcode_value' and Date ='$date'";

}
else
{
$sql2 = "insert into `letter_count` (Barcode, Date, Letter_count) values ('$barcode_value','$date',1)";
}



mysql_query($sql2);

echo "Letter Count Updated for barcode: ".$barcode_value;
?>

lubosdz

17.12.2016 22:49
# 53 Reply to lubosdz    
 

Chinthika Rathnayake chinthika.jayani@gmail.com wrote on 17.12.2016 19:57:
sir,I have coded to get the scanned barcode from barcode reader in to a php code in PC. I want to know how can i insert the number pattern of the barcode into the php code as a text.Above is my php code.i need to assign the number patter in to the barcode_value variable.please help me with this.
Hi, please read how barcode works in the article above - it is all described there. You need to:

1. install your barcode drivers into your PC
2. create HTML form (web page) with one input text field
3. focus the text field (e.g. place cursor into text input)
4. scan any barcode -> decrypted character sequence will appear in the text field and HTML form will be automatically submitted (if you configured your barcode setting to append CRLF to the barcode string). That's it.

Hans AT be-web

23.12.2016 12:35
# 54 Reply to Hans  AT  be-web    
 

This my code for using two fields before submitting the form. This is how is works.
- set focus on field one
- scanner sets value in field one
- the attached carriage return (keycode 13) sets the focus on field two
- if field two receives the carriage return the form is submitted.

I hope this is helpfull for someone.

Code:
<?php $post = 'geen invoer'; if (isset($_POST) && count($_POST) > 0) { $post = $_POST; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> var $ = jQuery; $(document).ready(function(){ $('form').submit(function(e) { e.preventDefault(); }); $('.invoer1').focus(); $('input').keypress(function(event) { var keycode = (event.keyCode ? event.keyCode : event.which); if (keycode == '13') { if ($(this).attr('class') == 'invoer2') { $('form').unbind().submit(); } else { $(this).next('input').focus(); } } }); }); </script> </head> <body> <form action="test.php" method="post"> <input name="invoer1" class="invoer1" type="text" /> <input name="invoer2" class="invoer2" type="text" /> <input type="submit" value="ga" /> </form> <?php print '<pre>'; var_dump($post);die; ?> </body> </html>

indarsugiarto

02.02.2017 05:30
# 55 Reply to indarsugiarto    
 

sorry, but i dont understanding about action="search.php".. where is the code??
thx

indarsugiarto

02.02.2017 05:32
# 56 Reply to indarsugiarto    
 

indarsugiarto wrote on 02.02.2017 05:30:
sorry, but i dont understanding about action="search.php".. where is the search.php code??
thx

hans AT be-web DOT nl

11.05.2017 15:41
# 57 Reply to hans AT be-web DOT nl    
 

"search.php" is the page with the code to handle the form request. The name of that file can have any name you like. In my code above it's test.php.

Pradeep yadav

24.05.2017 13:15
# 58 Reply to Pradeep yadav    
 

hii
Thanks for sharing the article it helps me a lot
sir i want to know that suppose i read sting as "400200"
here 400 is cost price and 200 is cost price so can u plz tell how we divide
string for two text box one for sale price and another for cost price.

riad35400 AT hotmail DOT fr

27.10.2017 12:38
# 59 Reply to riad35400 AT hotmail DOT fr    
 

hello,
How to use motorola PDA terminal in language PHP,
Motorola PDA in below link

Your Motorola-Symbol-MC9190-G90SWEYA6WR-Barcode-Scanner

praveena usurupati

01.03.2018 06:38
# 60 Reply to praveena usurupati    
 

I am working on barcode scanner for final year project.Can you please tell me how to catch the scanned barcode using the above this.focus() and send it to the next php page

the-_-prince AT live DOT com

23.01.2019 08:43
# 61 Reply to the-_-prince AT live DOT com    
 

thanks a lot bro , i didn't imagine is that simple :D

jinojacob15gmail DOT com

20.02.2019 13:51
# 62 Reply to jinojacob15gmail DOT com    
 

if there are multiple data incoming from barcode scanning device, how it will be rendered on the browser since only one input field is focused ? please answer this .

jinojacob15gmail DOT com

20.02.2019 14:02
# 63 Reply to jinojacob15gmail DOT com    
 

with reference to the above question , Im asking if the data is in JSON format , How it will be rendered in a single input field as barcodes can give multiple data regarding a product .

Cristopher

16.08.2019 13:58
# 64 Reply to Cristopher    
 

You POST the data in the input to PHP, $_POST

pirs@leosys.in wrote on 25.01.2013 10:11:
but where is php code that actually reads the bar code; any download links? please suggest

Prashanth Jhetre

28.08.2019 10:32
# 65 Reply to Prashanth Jhetre    
 

Pradeep yadav wrote on 24.05.2017 13:15:
hii
Thanks for sharing the article it helps me a lot
sir i want to know that suppose i read sting as "400200"
here 400 is cost price and 200 is cost price so can u plz tell how we divide
string for two text box one for sale price and another for cost price.
hi Pradeep,

Have you got answer for this problem? I am looking for suggestions on similar issue.

lubosdz

28.08.2019 11:26
# 66 Reply to lubosdz    
 

Prashanth Jhetre wrote on 28.08.2019 10:32:
Pradeep yadav wrote on 24.05.2017 13:15:
hii
Thanks for sharing the article it helps me a lot
sir i want to know that suppose i read sting as "400200"
here 400 is cost price and 200 is cost price so can u plz tell how we divide
string for two text box one for sale price and another for cost price.
hi Pradeep,
Have you got answer for this problem? I am looking for suggestions on similar issue.
Hi guys,
this has nothing to do with barcode scanner.
You must know how to process submitted barcode on server side.
For example you must split received barcode string with substr() or preg_match() or preg_split() etc function. Few examples:
Code:
$number1 = substr($barcode, 0, 3); $number2 = substr($barcode, 3);
Code:
list($number1, $number2) = explode("00", $barcode);
Code:
$validNumbers = preg_split("/[1-9]+/", $barcode);
It all depends what contains scanned barcode string. You must write proper PHP code to apply proper logic.

Leave your comment..
Email will be converted into something like [michael AT gmail DOT com]
Note: Offensive and unrelated comments will be deleted.
Please enter result from the picture above.