Jump to content

Code not displaying properly


jefrat72

Recommended Posts

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.

Link to comment
Share on other sites

[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>
<?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>[/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--]
Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.