klaxmi1 Posted April 1, 2008 Share Posted April 1, 2008 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 More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 That usually means that the webserver your using doesn't know how to process PHP or you're invoking the file incorrectly. How are you invoking the script? Ken Link to comment https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506078 Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 Please, enclose your script in [ code ] and [ /code ] Also, you are redefining $total over and over again. A variable can only store more than one value at a time if it is an array... you can instead use $total[] to define a new array entry Link to comment https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506082 Share on other sites More sharing options...
klaxmi1 Posted April 1, 2008 Author Share Posted April 1, 2008 im sorry im really new to php, so not really sure what invoking means. also how do i go about creating an array? Link to comment https://forums.phpfreaks.com/topic/98906-need-help/#findComment-506089 Share on other sites More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 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 More sharing options...
klaxmi1 Posted April 1, 2008 Author Share Posted April 1, 2008 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 More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.