The Online Ticket Booth

weaverchurchSoftware and s/w Development

Aug 15, 2012 (5 years and 2 months ago)

276 views


The Online Ticket Booth

Creating a small web application using PHP


Brian Maldonado

Brian.Maldo@gmail.com




The

purpose of this
tutorial

is to teach beginning programmers how to use PHP with an HTML form in order
to create a small web application th
at accepts and processes requests for sports game tickets.

This manual will
help you to get prepared with the proper materials and software in order to follow the video tutorial online.

2


Table of Contents

Introduction

................................
................................
................................
........

3

List of Materials

................................
................................
................................
..

5

Before You Be
gin…

................................
................................
..............................

6

Download and Install NetBeans 6.7.1

................................
................................
.

6

Download and Install WampServer 2.0i

................................
..............................

7

Create a new project in NetBeans 6.7.1

................................
..............................

8

Creating a new PHP file in

NetBeans 6.7.1


................................
........................

13

Additional Resources


................................
................................
........................

14

Contact Information

................................
................................
..........................

14

3


Introduction


The purpose of thi
s video is to teach beginning programmers how to use PHP with an HTML
form in order to c
reate a small web application that accepts and processes requests for sports
game tickets.

The application will consist of two files:

File

One

(index.php)

will be a sta
ndards
-
compliant HTML page with a form to collect user
input.


The form will collect the following information in POST format:



First name (text entry)



Last name (text entry)



Number of seats requested (dropdown containing values for 1


30)



Are these studen
t tickets? (checkbox)



Preferred seating section


upper section or lower section (radio buttons)



Home state (dropdown listing all 50 states)



A submit button at the bottom

of the form




4



File

Two

(process.php)

will

be

the

action

file

and it will process
the input according to the
following specifications:


The file will contain three functions:

1.

The first function will accept two parameters: first name and last name.


It will trim the
whitespace from both parameters, and then check to make sure neither is
an empty
string.


If either is an empty string, the function will return the string “error”.


Otherwise, it will return the first name and last name concatenated into one string with
a space between the names (
$first_name

.





.

$last_name)


2.

The second fu
nction will accept two parameters: number of seats requested and seat
cost.


It will trim the whitespace from both parameters, and then check to make sure
both are actually numeric values using

is_numeric()
.


If both are numeric, it will return
the product

of both
values
.


Otherwise, it will return the string, “error”.


3.

The third function will perform the following actions:



Declare a variable.


Call it

$base_seat_price

and set it to

30.00

(thirty dollars,
that is).



Run the first function, sending it the fir
st name and last name you collected from
the form.



Run the second function, sending it the number of seats you collected from the
form and the

$base_seat_price

variable.


Collect the returned value as the
variable,

$ticket_price
.



If either of the first two

functions return an error, print an error on the screen
and halt execution using the

exit()

function.



If the student tickets checkbox was checked, apply a 10% discount to the
ticket_price.



If the upper section was chosen on the form, apply a 10% discount
to the ticket
price.



Print out the user’s full name, returned by the first function, and the
final

$ticket_price
.


Call the third function so that it runs when the file loads.

5


List of Materials


-

NetBeans IDE 6.7.1 or higher (
http://netbeans.org/downloads/
).

-

WampServer 2.0i or higher (
http://www.wampserver.com/en/download.php
)

6


Before You Begin…

Download and install NetBeans IDE 6.7.1


Go to
http://netbeans.org/downloads/

and download NetBeans IDE 6.7.1. Make sure to
download the full install. In the photo, the download button is highlighted red. After
downloading the installation file, run the file. From

here, follow the instructions within the
installation wizard in order to install NetBeans 6.7.1.




7


Download and install WampServer 2.0i


Go to
http://www.wampserver.com/en/download.php

and downl
oad WampServer 2.0i. After
downloading the installation file, run the file. From here, follow the instructions within the
installation wizard in order to install WampServer 2.0i.


8


Create a new project in NetBeans IDE 6.7.1


Open NetBeans IDE 6.7.1 and
select File → New Project. This can a
lso be done by pressing
Control + Shift + N.



9



In the next window, select the PHP folder under Categories and select PHP Application under
Projects (see image below). Click on the next button when you are finished.



10



Give the project a name (OnlineTicketBooth) and choose a directory on your hard drive to store
the two files we will be creating. In this example, I am storing my files in the directory
C:
\
wamp
\
www
\
OnlineTicketBooth
. This is the default directory t
hat WampServer 2.0i when it
is installed (the only difference is that we are adding OnlineTicketBooth to the end of it).
Also,
make sure that Default Encoding is set to UTF
-
8 (see image below). You can ignore the check
box at the bottom. We will not nee
d it for this tutorial. When you are finished, click Next.











11



Set the Run As option to Local Web Site (running on local web server). If this is not selected by
default, then click on the drop down menu and select this option. The project URL s
hould be
http://localhost/OnlineTicketBooth/
. Ignore the check box at the bottom. You will not need it
for this tutorial. At this point, make sure that the information below matches exactly (see
image
below). When you are finished, click on Finish.



12



When you select Finish you will be taken to the main workspace of NetBeans IDE 6.7.1. This is
where you will be creating your files. By default, NetBeans will create an index.php for
you (
see
image be
low). Since this will be provided for you, you can erase this file and replace it with the
index.php file provided with this tutorial.

To view the project, select the index.php file and click
on the play button (the green triangle right under Tools). Th
is will launch you index.php file.




13



Creating a new PHP file in NetBeans IDE 6.7.1


The process.php file however you will be making from scratch (just in case, I have included that
file for you too). To create a new file: right
-
click on the Source Fil
es folder, select New, and
select PHP File

(see image below).




14



In the window that pops up, name the file process.php and click on Finish (see image below).






Now, you are ready to begin the video tutorial. I hope that you have found this manual

very
useful. Good luck future programmers!


I have included a link to the PHP Documentation website. Here you will find a lot of useful tools
and tutorials that will make you a better PHP programmer.
I have
also
included my contact
information below in

case you have any additional questions I did not cover in this manual or in
the video.


Additional Resources

http://us.php.net/manual/en/language.functions.php


Contact
Information

Brian Maldonado

Brian.Maldo@gmail.com