Displaying barcode image in php page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jin
Forum Newbie
Posts: 1
Joined: Wed Mar 17, 2010 12:44 pm

Displaying barcode image in php page?

Post by jin »

hi guys. i'm new here...so i apologise if this has come up earlier.

i have a website in php its a for a customers at my hotel. they enter their details and its gets saved to my database on my server (wamp server). Once the data is stored in the database an automatic booking ID is created and assigned to a specific customer.

I have generated a barcode image that carries the customers details (booking ID). my problems is when a customer enters their details on my website, when they finish confirming their booking the barcode image is being saved in a folder. i wanted the image to be displayed on a webpage, but i do not know how to do this....the code is below

Many thanks

page where barcode is being created...it is called the thank you.php page


<?php
session_start();
$_SESSION['firstname']= $_GET['firstname'];
$_SESSION['lastname']= $_GET['lastname'];
$_SESSION['address']= $_GET['address'];
$_SESSION['email']= $_GET['email'];

/*
Mysql query
CREbookingid;ATE TABLE `booking`. (
`bookingid` INT( 10 ) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR( 100 ) NOT NULL ,
`lastname` VARCHAR( 100 ) NOT NULL ,
`address` VARCHAR( 200 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
`room` VARCHAR( 40 ) NOT NULL ,
`checkin` VARCHAR( 40 ) NOT NULL ,
`checkout` VARCHAR( 40 ) NOT NULL
) ENGINE = MYISAM

ALTER TABLE `booking` CHANGE `bookingid` `bookingid` INT( 10 ) NOT NULL AUTO_INCREMENT

*/

//Store the data in Mysql
$host ="localhost";
$username ="root";
$password ="1234";
$database ="booking table";

$connect = mysql_connect($host, $username, $password) or die ("Connection to Mysql failed");
$selectdb = mysql_select_db($database);
$query = "INSERT INTO booking (firstname, lastname, address, email, room, checkin, checkout) VALUES ( '".$_SESSION['firstname']."','".$_SESSION['lastname']."','".$_SESSION['address']."','".$_SESSION['email']."','".$_SESSION['room']."','".$_SESSION['checkin']."','".$_SESSION['checkout']."')";

$firequery = mysql_query($query) or die ("Query fired Failed");


//Get bookingid
$connect = mysql_connect($host, $username, $password) or die ("Connection 2 to Mysql failed");
$selectdb = mysql_select_db($database);
$query = "select bookingid from booking where email = '".$_SESSION['email']."'";
$firequery = mysql_query($query) or die ("Query 2 fired Failed");

$result = mysql_fetch_array($firequery);

$bookingid = $result['bookingid'];
mysql_close($connect);


require("barcode.inc.php");
$bar= new BARCODE();
if($bar==false)
die($bar->error());
$bar->setSymblogy("UPC-A");
$bar->setHeight(50);
$bar->setFont("arial");
$bar->setScale(2);
$bar->setHexColor("#000000","#FFFFFF");
$barnumber=$bookingid;
$name = "barcode_".$bookingid;
$file= "jpg";
$bar->genBarCode($barnumber,$file,$name);
?>



Page where i want the barcode to be displayed...it is called login_success.php


<?
session_start();
if($_SESSION['myusername'] != ''){
header("location:main_login.php");
}
?>
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Displaying barcode image in php page?

Post by infolock »

If it is (indeed) creating the image, the only thing you need is to have the image inside your htdocs folder. Then it's just a matter of navigating to it via the url or loading it with img src.
Post Reply