jefrat72 Posted May 9, 2006 Share Posted May 9, 2006 Brand new user here, trying to learn out of a book "PHP & MySQL Web Development".It has you open their prebuilt html file (off the cd) with your browser and you then enter the number of product you purchased (in this case tires/sparkplugs&oil). when you click on the "Submit Order" button it calls this script that I've written by the books instruction:[!--coloro:#6633FF--][span style=\"color:#6633FF\"][!--/coloro--]<?php// create short variable names$tireqty = $_POST['tireqty'];$oilqty = $_POST['oilqty'];$sparkqty = $_POST['sparkqty'];?><html><head> <title>Bob's Auto Parts - Order REsults</title> </head><body><h1>Bob's Auto Parts</h1><h2>Order Results</h2><?phpecho '<p>Order processed at ';echo date('H:i, jS F');echo '</p>;?></body></html>echo '<p>Your order is as follow: </p>';echo $tireqty.' tires<br />';echo $oilqty.' bottles of oil<br />';echo $sparkqty.' spark plugs<br />';[!--colorc--][/span][!--/colorc--]It's supposed to say the date your order is and the amounts you ordered, like this:[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]Bob's Auto PartsOrder ResultsOrder processed at 4:05, 5th MayYour order is as follows: 1 tires2 bottles of oil3 spark plugs[!--colorc--][/span][!--/colorc--]But I get this:[!--coloro:#6633FF--][span style=\"color:#6633FF\"][!--/coloro--]Bob's Auto PartsOrder ResultsOrder processed at '; echo date('H:i, jS F'); echo '; ?> echo 'Your order is as follow: '; echo $tireqty.' tires'; echo $oilqty.' bottles of oil'; echo $sparkqty.' spark plugs';[!--colorc--][/span][!--/colorc--]Any idea why? I'm on a PCBSD machine using their PAMP package which contains Apache 2.2.0, MySQL 5.0.18 and PHP 5.1.2. I'm using Quanta Plus to write/edit the script. I've used Firefox and Opera to open this and get the same result both times. Hope this is clear enough, thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/ Share on other sites More sharing options...
jeremywesselman Posted May 9, 2006 Share Posted May 9, 2006 [code] <?php// create short variable names$tireqty = $_POST['tireqty'];$oilqty = $_POST['oilqty'];$sparkqty = $_POST['sparkqty'];?><html><head><title>Bob's Auto Parts - Order REsults</title></head><body><h1>Bob's Auto Parts</h1><h2>Order Results</h2><?phpecho '<p>Order processed at ';echo date('H:i, jS F');echo '</p>';echo '<p>Your order is as follow: </p>';echo $tireqty.' tires<br />';echo $oilqty.' bottles of oil<br />';echo $sparkqty.' spark plugs<br />';?></body></html>[/code]You need to move the ?></body></html> tags underneath the rest of the echos.You also need a closing quote on [b]echo '</p>[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--];[/b].[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--] Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-34744 Share on other sites More sharing options...
jefrat72 Posted May 9, 2006 Author Share Posted May 9, 2006 Ok, did what you said (thanks), and see what you mean. But I still am getting the same output. Here's the code as it is now:<?php// create short variable names$tireqty = $_POST['tireqty'];$oilqty = $_POST['oilqty'];$sparkqty = $_POST['sparkqty'];?><html><head><title>Bob's Auto Parts - Order REsults</title></head><body><h1>Bob's Auto Parts</h1><h2>Order Results</h2><?phpecho '<p>Order processed at ';echo date('H:i, jS F');echo '</p>';echo '<p>Your order is as follows: </p>';echo $tireqty.' tires<br />';echo $oilqty.' bottles of oil<br />';echo $sparkqty.' spark plugs<br />';?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-34755 Share on other sites More sharing options...
.josh Posted May 9, 2006 Share Posted May 9, 2006 i suspect that you have your file saved as blah.html the server will not parse your script unless it recognizes the file as a php file. unless you set the mime type .htm or .html to be processed as php, it will dump out your script as if it were plain old text.change your file name to blah.php Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-34759 Share on other sites More sharing options...
jefrat72 Posted May 10, 2006 Author Share Posted May 10, 2006 thanks for the reply. The prebuilt file is named "orderform.html", the script I wrote following the book is named "processorder.php" The "processorder.php" is the one displaying incorrectly. That's named correctly isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-34908 Share on other sites More sharing options...
wildteen88 Posted May 10, 2006 Share Posted May 10, 2006 You said you was running the code of the CD with a browser. Then that will be your problem. You cannot run php code within a web browser as it doesnt understand PHP code. A web browser only understands HTML, CSS and Javascript coding lanagages.Now in order to run your php file you need to install a server on to your PC. You can do this easily by installing a software package called WAMP. You can WAMP get [a href=\"http://www.wampserver.com/en/index.php\" target=\"_blank\"]here[/a]. It is free to download and use. Once that is installed open up your browser and type in [a href=\"http://localhost/\" target=\"_blank\"]http://localhost/[/a] Now copy all the php files from the CD to the folder where you have to store your PHP files to be seen by the Apache server. Which I believe is something along the lines of C:\program files\Apache Group\Apache 2\htdocsNow when you go to [a href=\"http://localhost/\" target=\"_blank\"]http://localhost/[/a] again you should see you php files now just click on the php file you want to run. WAMP should now parse your PHP files and an output should be displayed in the web browser. Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-34913 Share on other sites More sharing options...
jefrat72 Posted May 10, 2006 Author Share Posted May 10, 2006 Thanks wildteen88, That answered the question. Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-35031 Share on other sites More sharing options...
wildteen88 Posted May 10, 2006 Share Posted May 10, 2006 No problem! I thought that was the case. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/9423-code-not-displaying-properly/#findComment-35043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.