Hi..
I have problem with my system which is the bar code image cannot been display after the bar code generate from the database.
can anyone show me the correct way to call the data from database to generate and display in my system?
when user click view card in list_contract_worker.php, the view_card.php display the information and also the bar code image so they can print the barcode image with the information in this page.

this is my code.

list_contract_worker.php

<head>
<script src="datetimepicker_css.js"></script>
</head>

<br> <script>
/*Current date script credit: 
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("&nbsp;<small><font color='black' face='Tahoma'><b>"+dayarray[day]+", "+daym+" "+montharray[month]+" "+year+" </b></font></small>")
        </script></br><p></p>

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("pqs", $con);
$result = mysql_query("SELECT * FROM contractworkerdb");
?>

<table width="694" border="0" align="center">
  <tr>
    <th height="48" colspan="7" scope="col">List of Contract Worker </th>
  </tr>
  <tr>
    <th width="166" scope="row">Name</th>
    <td width="94"><div align="center"><strong>Barcode ID </strong></div></td>
    <td width="93"><div align="center"><strong>Company</strong></div></td>
    <td width="93"><div align="center"><strong>View Card </strong></div></td>
    <td width="87"><div align="center"><strong>View</strong> <strong>Profile</strong> </div></td>
    <td width="62"><div align="center"><strong>Update</strong></div></td>
    <td width="69"><div align="center"><strong>Delete</strong></div></td>
  </tr>
  <?php while($row = mysql_fetch_array($result))
				{

				?>
  <tr>
    <th scope="row"><div align="center"><?php echo $row['Name']; ?>&nbsp;</div></th>
    <td><div align="center"><?php echo $row['barcode_id']; ?>&nbsp;</div></td>
    <td><div align="center"><?php echo $row['Company']; ?>&nbsp;</div></td>
    <td><div align="center"><a href="view_card.php?ref1=<?php echo $row['contract_id'];?>">view</a></div></td>
    <td><div align="center"><a href="view_data.php?ref1=<?php echo $row['contract_id'];?>">view</a></div></td>
    <td><div align="center"><a href="update_data.php?ref1=<?php echo $row['contract_id'];?>">update</a></div></td>
    <td><div align="center"><a href="delete_data.php?id=<?php echo $row['contract_id'];?>">delete</a></div></td>
  </tr>
  <?php }?>
  <tr>
    <th colspan="7" scope="row">&nbsp;</th>
  </tr>
  <tr>
    <th colspan="7" scope="row"><input name="print" type="submit" id="print" value="Print" />
        <input name="export" type="submit" id="export" value="Export" /></th>
  </tr>
</table>
<?php 
mysql_close($con);
?>

view_card.php

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("pqs", $con);
$ref1 = $_REQUEST['ref1'];
//$barcode_id = $_POST['barcode_id'];
$b = barcode_id[$ref1];  
$result = mysql_query("SELECT Name, Ic_no, barcode_id, Department, filep FROM contractworkerdb WHERE contract_id = '$ref1' LIMIT 0,1");
?>

<form name="form1" method="post" action="index.php?page=view_card.php">

<p>&nbsp;</p>
<table width="636" border="0" align="center">
  <tr>
  
  <?php while($row = mysql_fetch_array($result))
				{

				?>
				
<input type="hidden" name="contract_id" value="<?php echo $ref1; ?>" />
    <th colspan="3" scope="col"><img src="<?php echo $row['filep'];?>" alt="" /></th>
  </tr>
  <tr>
    <th width="166" scope="row"><div align="right">Name</div></th>
    <td width="10"><div align="center">:</div></td>
    <td width="446"><?php echo $row['Name']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">IC No. </div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['Ic_no']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">Barcode ID </div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['barcode_id']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">Department</div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['Department']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th colspan="3" scope="row">
	
	<?
 
	echo "<div class=\"noscreen\" align=\"center\"><span class=\"bigtxt\">$b</span><br><img src=\"barcode.php?barcode=$b&width=300&height=80\"></div>";	
 ?>
		
&nbsp;</th>
  </tr>
  <?php }?>
      <?php 
mysql_close($con);
?>
</table>
</form>

help me please.. :(

tcpdf libraries are something to ready made using which u can generate barcode reports.
If you still want to use your own logic, then specify teh exact problem, which part of code is failing in your case.

Hi

<img src=\"barcode.php?barcode=$b&width=300&height=80\">

The above the line should be replace as below

<img src="barcode.php?codetype=Code39&size=50&text=$b" alt="$b" />

you have missed the parameters where the value has to pass

I already replace it with the new code.
There is no error occur..
But the problem is the image of barcode not display..
Can u explain me why the image of barcode is not display?

You can see my new code here..

view_card.php

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("pqs", $con);
$ref1 = $_REQUEST['ref1'];
//$barcode_id = $_POST['barcode_id'];
//$b = barcode_id[$ref1];  
$result = mysql_query("SELECT Name, Ic_no, barcode_id, Department, filep FROM contractworkerdb WHERE contract_id = '$ref1' LIMIT 0,1");
?>

<form name="form1" method="post" action="index.php?page=view_card.php">

<p>&nbsp;</p>
<table width="636" border="0" align="center">
  <tr>
  
  <?php while($row = mysql_fetch_array($result))
				{

				?>
				
<input type="hidden" name="contract_id" value="<?php echo $ref1; ?>" />
    <th colspan="3" scope="col"><img src="<?php echo $row['filep'];?>" alt="" /></th>
  </tr>
  <tr>
    <th width="166" scope="row"><div align="right">Name</div></th>
    <td width="10"><div align="center">:</div></td>
    <td width="446"><?php echo $row['Name']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">IC No. </div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['Ic_no']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">Barcode ID </div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['barcode_id']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th scope="row"><div align="right">Department</div></th>
    <td><div align="center">:</div></td>
    <td><?php echo $row['Department']; ?>&nbsp;</td>
  </tr>
  <tr>
    <th colspan="3" scope="row">
	<div class=\"noscreen\" align=\"center\"><span class=\"bigtxt\"><?php echo $row['barcode_id']; ?></span><br><img src=\"barcode.php?barcode=&width=300&height=80&text=<?php echo $row['barcode_id']; ?> alt="<?php echo $row['barcode_id'];?>" \"></div>
&nbsp;</th>
  </tr>
  <?php }?>
      <?php 
mysql_close($con);
?>
</table>
</form>

Can anyone help me to find the error?
It's show the page but the the image of barcode is not appear..

Hello Friend

you missed the value of barcode

<div class=\"noscreen\" align=\"center\"><span class=\"bigtxt\"><?php echo $row['barcode_id']; ?></span><br><img src=\"barcode.php?[B]barcode=[/B]&width=300&height=80&text=<?php echo $row['barcode_id']; ?> alt="<?php echo $row['barcode_id'];?>" \"></div>

What do you mean by miss the value of barcode?
Can you explain it to me?

Hi

barcode.php

<?php

/*
 *  Author:  David S. Tufts
 *  Company: Rocketwood.LLC
 *	  www.rocketwood.com
 *  Date:	05/25/2003
 *  Usage:
 *	  <img src="/barcode.php&text=testing" alt="testing" />
 */
	
	// Get pararameters that are passed in through $_GET or set to the default value
	$text = (isset($_GET["text"])?$_GET["text"]:"0");
	$size = (isset($_GET["size"])?$_GET["size"]:"20");
	$orientation = (isset($_GET["orientation"])?$_GET["orientation"]:"horizontal");
	$code_type = (isset($_GET["codetype"])?$_GET["codetype"]:"code128");
	$code_string = "";

	// Translate the $text into barcode the correct $code_type
	if(strtolower($code_type) == "code128")
	{
		$chksum = 104;
		// Must not change order of array elements as the checksum depends on the array's key to validate final code
		$code_array = array(" "=>"212222","!"=>"222122","\""=>"222221","#"=>"121223","$"=>"121322","%"=>"131222","&"=>"122213","'"=>"122312","("=>"132212",")"=>"221213","*"=>"221312","+"=>"231212",","=>"112232","-"=>"122132","."=>"122231","/"=>"113222","0"=>"123122","1"=>"123221","2"=>"223211","3"=>"221132","4"=>"221231","5"=>"213212","6"=>"223112","7"=>"312131","8"=>"311222","9"=>"321122",":"=>"321221",";"=>"312212","<"=>"322112","="=>"322211",">"=>"212123","?"=>"212321","@"=>"232121","A"=>"111323","B"=>"131123","C"=>"131321","D"=>"112313","E"=>"132113","F"=>"132311","G"=>"211313","H"=>"231113","I"=>"231311","J"=>"112133","K"=>"112331","L"=>"132131","M"=>"113123","N"=>"113321","O"=>"133121","P"=>"313121","Q"=>"211331","R"=>"231131","S"=>"213113","T"=>"213311","U"=>"213131","V"=>"311123","W"=>"311321","X"=>"331121","Y"=>"312113","Z"=>"312311","["=>"332111","\\"=>"314111","]"=>"221411","^"=>"431111","_"=>"111224","\`"=>"111422","a"=>"121124","b"=>"121421","c"=>"141122","d"=>"141221","e"=>"112214","f"=>"112412","g"=>"122114","h"=>"122411","i"=>"142112","j"=>"142211","k"=>"241211","l"=>"221114","m"=>"413111","n"=>"241112","o"=>"134111","p"=>"111242","q"=>"121142","r"=>"121241","s"=>"114212","t"=>"124112","u"=>"124211","v"=>"411212","w"=>"421112","x"=>"421211","y"=>"212141","z"=>"214121","{"=>"412121","|"=>"111143","}"=>"111341","~"=>"131141","DEL"=>"114113","FNC 3"=>"114311","FNC 2"=>"411113","SHIFT"=>"411311","CODE C"=>"113141","FNC 4"=>"114131","CODE A"=>"311141","FNC 1"=>"411131","Start A"=>"211412","Start B"=>"211214","Start C"=>"211232","Stop"=>"2331112");
		$code_keys = array_keys($code_array);
		$code_values = array_flip($code_keys);
		for($X = 1; $X <= strlen($text); $X++)
		{
			$activeKey = substr( $text, ($X-1), 1);
			$code_string .= $code_array[$activeKey];
			$chksum=($chksum + ($code_values[$activeKey] * $X));
		}
		$code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]];

		$code_string = "211214" . $code_string . "2331112";
	}
	elseif(strtolower($code_type) == "code39")
	{
		$code_array = array("0"=>"111221211","1"=>"211211112","2"=>"112211112","3"=>"212211111","4"=>"111221112","5"=>"211221111","6"=>"112221111","7"=>"111211212","8"=>"211211211","9"=>"112211211","A"=>"211112112","B"=>"112112112","C"=>"212112111","D"=>"111122112","E"=>"211122111","F"=>"112122111","G"=>"111112212","H"=>"211112211","I"=>"112112211","J"=>"111122211","K"=>"211111122","L"=>"112111122","M"=>"212111121","N"=>"111121122","O"=>"211121121","P"=>"112121121","Q"=>"111111222","R"=>"211111221","S"=>"112111221","T"=>"111121221","U"=>"221111112","V"=>"122111112","W"=>"222111111","X"=>"121121112","Y"=>"221121111","Z"=>"122121111","-"=>"121111212","."=>"221111211"," "=>"122111211","$"=>"121212111","/"=>"121211121","+"=>"121112121","%"=>"111212121","*"=>"121121211");

		// Convert to uppercase
		$upper_text = strtoupper($text);

		for($X = 1; $X<=strlen($upper_text); $X++)
		{
			$code_string .= $code_array[substr( $upper_text, ($X-1), 1)] . "1";
		}

		$code_string = "1211212111" . $code_string . "121121211";
	}
	elseif(strtolower($code_type) == "code25")
	{
		$code_array1 = array("1","2","3","4","5","6","7","8","9","0");
		$code_array2 = array("3-1-1-1-3","1-3-1-1-3","3-3-1-1-1","1-1-3-1-3","3-1-3-1-1","1-3-3-1-1","1-1-1-3-3","3-1-1-3-1","1-3-1-3-1","1-1-3-3-1");

		for($X = 1; $X <= strlen($text); $X++)
		{
			for($Y = 0; $Y < count($code_array1); $Y++)
			{
				if(substr($text, ($X-1), 1) == $code_array1[$Y])
					$temp[$X] = $code_array2[$Y];
			}
		}

		for($X=1; $X<=strlen($text); $X+=2)
		{
			$temp1 = explode( "-", $temp[$X] );
			$temp2 = explode( "-", $temp[($X + 1)] );
			for($Y = 0; $Y < count($temp1); $Y++)
				$code_string .= $temp1[$Y] . $temp2[$Y];
		}

		$code_string = "1111" . $code_string . "311";
	}
	elseif(strtolower($code_type) == "codabar")
	{
		$code_array1 = array("1","2","3","4","5","6","7","8","9","0","-","$",":","/",".","+","A","B","C","D");
		$code_array2 = array("1111221","1112112","2211111","1121121","2111121","1211112","1211211","1221111","2112111","1111122","1112211","1122111","2111212","2121112","2121211","1121212","1122121","1212112","1112122","1112221");

		// Convert to uppercase
		$upper_text = strtoupper($text);

		for($X = 1; $X<=strlen($upper_text); $X++)
		{
			for($Y = 0; $Y<count($code_array1); $Y++)
			{
				if(substr($upper_text, ($X-1), 1) == $code_array1[$Y] )
					$code_string .= $code_array2[$Y] . "1";
			}
		}
		$code_string = "11221211" . $code_string . "1122121";
	}

	// Pad the edges of the barcode
	$code_length = 20;
	for($i=1; $i <= strlen($code_string); $i++)
		$code_length = $code_length + (integer)(substr($code_string,($i-1),1));

	if(strtolower($orientation) == "horizontal")
	{
		$img_width = $code_length;
		$img_height = $size;
	}
	else
	{
		$img_width = $size;
		$img_height = $code_length;
	}

	$image = imagecreate($img_width, $img_height);
	$black = imagecolorallocate ($image, 0, 0, 0);
	$white = imagecolorallocate ($image, 255, 255, 255);

	imagefill( $image, 0, 0, $white );

	$location = 10;
	for($position = 1 ; $position <= strlen($code_string); $position++)
	{
		$cur_size = $location + ( substr($code_string, ($position-1), 1) );
		if(strtolower($orientation) == "horizontal")
			imagefilledrectangle( $image, $location, 0, $cur_size, $img_height, ($position % 2 == 0 ? $white : $black) );
		else
			imagefilledrectangle( $image, 0, $location, $img_width, $cur_size, ($position % 2 == 0 ? $white : $black) );
		$location = $cur_size;
	}
	// Draw barcode to the screen
	header ('Content-type: image/png');
	imagepng($image);
	imagedestroy($image);
?>

16th line in my barcode.php file you can able to see the $code_type variable, it will help to generate the barcode format.

in you scipt you have written barcode= on line 51.
instead of that barcode if you use codetype=Code39

So i keep the code as below

<div class="noscreen" align="center"><span class="bigtxt"><?php echo $row['barcode_id']; ?></span><br><img src="barcode.php?codetype=Code39&width=300&height=80&text=<?php echo $row['barcode_id']; ?>" alt="<?php echo $row['barcode_id'];?>" \></div>

Thanks rpv_sen.
Its work! :)

thank u

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.