Jump to content

need help!!!!


klaxmi1

Recommended Posts

i dont know why my code isnt working, im not an experienced programmer...so any help would be much appreciated

 

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

 

<head>

 

<meta http-equiv= "content-type"

content="text/html; charset=iso-8859-1" />

 

<title>SportyWear - Order Summary</title>

 

</head>

 

<body>

<h1>SportyWear</h1>

<h2>Order Summary</h2>

 

<?php // Script 4.2 - processorder.php

 

ini_set('display_errors', 1);

 

//obtaining variable values

$title = $_POST['title'];

$name = $_POST['name'];

$housename = $_POST['house'];

$address1 = $_POST['address1'];

$address2 = $_POST['address2'];

$address3 = $_POST['address3'];

$postcode = $_POST['postcode'];

$socks = $_POST['socks'];

$bottle = $_POST['bottle'];

$bag = $_POST['bag'];

$postage = $_POST['postage'];

 

 

//declare prices

$bottle_price = "29.99";

$bag_price = "29.99";

$postage_price = "5.99";

 

//calculate prices

//price of total bottles ordered

$total = ($total + ($bottle_price * $bottle));

//price of total bags ordered

$total = ($total + ($bag_price * $bag));

//price of total socks ordered

$total = ($total + ($socks_price * $socks));

//total price plus postage

$total = ($total + ($total + $postage));

//price excluding tax

$total = $extax;

//calculate tax total

$total = $total * 1.175;

//total including tax

$total = $inctax;

 

 

 

print <b>$total</b>;

 

?>

 

 

</body>

</html>

 

 

above is my code but every time i run it

 

it just shows this in a webpage

 

SportyWear

Order Summary

$total; ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/98906-need-help/
Share on other sites

What did you type in the browser to get your script to run? Or did you double-click the file name. If you double clicked, that's the problem, since PHP needs to processed by the webserver and double clicking will not do that.

 

In your case, you don't need an array, just 2 different variables:

<?php
$total = 0;
//calculate prices
//price of total bottles ordered
$total += $bottle_price * $bottle;
//price of total bags ordered
$total += $bag_price * $bag;
//price of total socks ordered
$total += $socks_price * $socks;
//total price plus postage
$total += $total + $postage;
//price excluding tax
$extax = $total;
//calculate tax total
$inctac = $total * 1.175;

echo $extax . ' ' . $inctax;
?>

If I've understood what you're trying to do.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506097
Share on other sites

Sorry I didn't really explain what I was trying to achieve. Basically, I need to multiply the quantity of each item by its price (which I hope I have declared correctly) and then add postage... and then display the total but I thought I was going about it the right way  :(

 

Also, I'm running the file from Notepad++ and I believe I have access to a server(?)

Link to comment
https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506104
Share on other sites

In order for your PHP script to be processed it must be seen by the server first before being sent to the browser. You can run an Apache server on your Windows machine by downloading and installing a wamp packaged. I use xampp. Once the package is installed, you can then enter the url http://localhost/path/to/your/file.php.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506127
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.