View Full Version : Simple Php Help

01-28-2007, 02:46 AM
Okay I am taking a PHP class I have the HTML document already I just dont understand the php part well the bold part maybe some one could help Please!

Create two files (1) an HTML file, and (2) a PHP file. The HTML file should be a form that collects order information on 3 products -- shirts ($10), pants ($20), and shoes ($30). The PHP file should have 7 variables -- shirts, shirtprice, pants, pantprice, shoes, shoeprice, & total. If any customer purchases 3 or more of any item, you should award a 10 percent discount. You must use the conditional statement of your choice to apply the discount. The PHP page must display the information on the browser screen. Also, calculate the grand total cost to the customer.

The discount is not applied to the total, but to the individual items bought.

I also attach the html file and the php file I created even though its wrong maybe some one can help me out Thanks! :thumbsup:

01-28-2007, 03:30 AM
A form is like a contact form that you see on websites ....

<form action="myphpscript.php" method="post">
Shoes $20<br>
How many would you like: <input type="text" name="shoes" value=""><br><br>
Shirts $25<br>
How many would you like: <input type="text" name="shirts" value=""><br><br>
<input type="submit" name="submit" value="Place Order">

Then, it calls a PHP script and the variables are read by the script.
The PHP script then does the conditional statements and adds things up.

So, if you search Google for "PHP form processing", you'll get all the
code you need to read form variables and output a page.

... hope that gets you started.

01-28-2007, 05:00 AM
I am confused about the 7 variables I can understand this

$shirtsprice= 10.00
$shoesprice=30.00 ?>

But where do I ge the shirts, pants, shoes, and total varibables from?

what do I set then equal to? Im lost

Maybe Im makin this harder than what it is and I have a book but its not helping either

01-28-2007, 07:42 AM
The HTML file will contain the form, which is where the user will input data.

html file

<form method="post" action="gotophpfile.php">
Quantity of Shirts: <input type="text" name="shirts">
Quantity of Pants: <input type="text" name="pants">
Quantity of Shoes: <input type="text" name="shoes">

The purpose of creating the PHP file is to interpret the information and return the information with a total cost.

php file


if ($_POST['shirts'] >= 3 || $_POST['pants'] >=3 || $_POST['shoes'] >=3)
$discountMult = .9;
else { $discountMult = 1; }

$total = (($_POST['shirts'] * $shirtsPrice) +
($_POST['pants'] * $pantsPrice) +
($_POST['shoes'] * $shoesPrice)) * $discountMult;

echo "
Shirts: " . $_POST['shirts'] . "x Price: " . $shirtsPrice . " <br>
Pants: " . $_POST['pants'] . "x Price: " . $pantsPrice . " <br>
Shoes: " . $_POST['shoes'] . "x Price: " . $shoesPrice . " <br>
Total: " . $total . " <br>


I did this in a hurry so if there are some errors let me know, but that's pretty much what you want.

01-28-2007, 04:29 PM
PB ...

This is really homework and we shouldn't give you the answers.

Why isn't your teacher showing you this basic HTML/PHP stuff?

That is a really poor reflection on your instructor.

Everything we're showing you is like HTML 101 ..
If you search Google, you'll find tutorials that show you exactly what to do.
If you're paying for this class, I'd ask for my money back.

01-28-2007, 10:00 PM
Yeah, I guess it was wrong of me to post your homework lol, but I will say this...

This assignment does seem kind of confusing and not perfectly clear, i don't know if this was the exact assignment or a paraphrase but the assignment is very unclear and does reflect badly on your professor.

01-29-2007, 09:21 PM
Im mean I know how to create the HTML I just didn't understand the PHP Im new at this and the class I am taking is a Online class so I can ask him but it will take him forever to email me back........ so I just decided to come here :thumbsup:

but I have another quetion where does the prices of the shirts, pants, shoes come in at (like the 10.00, 20.00, 30.00)

I don't work well just reading the book... I have to ask question

01-30-2007, 02:11 AM
You can include the prices within your form as
hidden variables, but that is a security risk,
so define the prices directly inside your PHP script.





echo $total;