Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, February 23, 2010

Make Progress Today

Gentlemen:
Regarding the Cash Register Project,
You should, by now, have the form finished and should be working on Page 2 of the assignment. Page 2 contains all the code.
Remember, the goal is to calculate the bill for the restaurant meal:
Here's a tip (Ha, get it? A "tip?").
OK, Several tips:

discount amount = (mealprice * discount decimal)
Discount decimial means a percentage (i.e., 10%) expressed as a decimal (i.e., 0.10)

bill = (mealprice - discount amount) + tax + tip.

Monday, February 22, 2010

Code Flowchart for Cash Reg!

Coding Flowchart

What follows is a Logical Flow of the PHP code, written in plain English, for the cash register program.

First rename the $_GET or $_POST variables. We do this to make them easier to work with in the code.



Note: Chkdisc is a special case, because it may be passed as a NULL (does not exist) value. Write code to set the chkdisc to a value > 0 if it is null.

Use a decimal, not a percent, when setting checkdisc



As of this point, you have 4 variables you are now working with:



$meal

$disc_perc (the decimal value, actually, of the discount)

$tax

$tip



Next, we use a SWITCH CASE statement to assign the value of the price to the meal. For example, if the meal chosen was SPAGHETTI, set the price to $5 or $14.50 or whatever you choose.



Note, we are “switching case,” i.e., checking the value of, the variable $meal



Next, we calculate the DOLLAR AMOUNT of the discount, using the value of the $disc_perc that we calculated earlier.



Note, the discount amount is calculated by multiplying:
$meal * $disc_perc



Next, we use simple math to calculate the BILL



Note: use $bill as the variable for holding the bill amount



Lastly, we print the variables onto the page using the ECHO statement.



The only catch here is the number format function, which I will show you, to print only two decimal places!

Thursday, February 11, 2010

Data Captcha!

Today we will be finishing up our lesson on capturing data using a php form. We will capture first name and last name and send them to a separate page for processing.
Remember the format for the variables we are capturing.
$_GET['fieldname']

or

$_POST['fieldname']

We will also rename variables today to make them simpler to use.

We will also do a bit of logical processing using an IF statement.

Friday, February 5, 2010

Code Red

Yesterday we learned about PHP coding. We wrote our first program and learned how to begin and end a php script.
We learned how to echo (print) output to the screen. We learned how to do basic addition and multiplication and we learned how to output line breaks in html and to include code to format an automatic date.
We also included one of the many $_SERVER global variables to give us information about the visitors' web address.

Today we will
a) declare variables...
b) make a form to capture and display information (and probably manipulate the data, too).

Wednesday, November 4, 2009

Invariably Passing...

Today we are learning to pass a variable from one PHP page to the next. Specifically, we are setting up a straight HTML form on the first page ("formtest.php") and sending the information to a second page ("formdisplay.php") when the user clicks "submit."

We created the the first page (the form, named "formtest.php") in Dreamweaver and used the point-and-click Design view interface to create the form (no coding needed). See form layout below:


Be sure to set the properties for various items as well as detailed below:
  1. To create the form (the form is indicated by the red dotted line), click Insert >> form >> form.
  2. Accept form1 as the name of the form; set the "action" of the form to be formdisplay.php
  3. Set the method to "GET." (see picture below)



  4. To insert the name field, click Insert >> Form >> Text Field. Set "Name" to "name," "Char Width" to 25 and "Max Chars" to 50. Be sure to put the text field INSIDE the form, i.e, the red dotted line.
  5. Insert the submit button: Click Insert >> Form >> Button. Accept the default name, etc. and press OK.
  6. Insert the reset button: Click Insert >> Form >> Button. Accept the defaults. Change the "action" for the button to "Reset form."
  7. Save the page.
Open "formdisplay.php" and enter the following code to display the output of the form from formtest.php:


To test the code, open formtest.php on our class webserver, type a name, and press submit. The name should display on the page called "formdisplay.php."

Thursday, October 29, 2009

Today we worked on creating our first PHP scripts. We also presented some notes on dynamic sites and the basics of PHP.
Here's our first script, which we wrote in notepad and saved in our K: drives. We were careful to name the page with a *.php extension.




The output of the above code should look something like this:



We also learned that PHP is a server-side language that is cross-platform, as shown in the diagram below:



Lastly, we learned that PHP stands, depending on whom you ask, for:
a) Hypertext Pre-Processor or...
b) Personal Home Page

PHP is used in over 22 million domains, has great security features, and is specially made to work hand-in-glove with the MySQL database system.
Plus, PHP is totally FREE!