Jump to content


Photo

Code not displaying properly


  • Please log in to reply
7 replies to this topic

#1 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 May 2006 - 08:08 PM

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>
<?php
echo '<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 Parts
Order Results
Order processed at 4:05, 5th May

Your order is as follows:
1 tires
2 bottles of oil
3 spark plugs[!--colorc--][/span][!--/colorc--]

But I get this:

[!--coloro:#6633FF--][span style=\"color:#6633FF\"][!--/coloro--]Bob's Auto Parts
Order Results
Order 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.



#2 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 09 May 2006 - 08:32 PM

<?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>
<?php
echo '<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>

You need to move the ?></body></html> tags underneath the rest of the echos.

You also need a closing quote on echo '</p>[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--];.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

#3 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 May 2006 - 09:07 PM

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>
<?php
echo '<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>


#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 09 May 2006 - 09:34 PM

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
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 10 May 2006 - 01:47 PM

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?

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 May 2006 - 02:05 PM

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\htdocs

Now 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.

#7 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 10 May 2006 - 06:52 PM

Thanks wildteen88, That answered the question.

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 May 2006 - 07:28 PM

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\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users