Page 1 of 1

Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 9:34 am
by Strike82
Hello everybody

I am a student and I am starting to learn the PHP. A strange thing is happeing when i try to execute any of the scripts.

For example I have these two snippets of code :

1: orderform.html

<html>
<head><title>Bob's Auto Parts</title></head>
<body>
<form action="processorder.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align="center"><input type="text" name="tireqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td>Oil</td>
<td align="center"><input type="text" name="oilqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align="center"><input type="text" name="sparkqty" size="3"
maxlength="3" /></td>
</tr>
<tr>
<td>How did you find Bob's?</td>
<td><select name="find">
<option value = "a">I'm a regular customer</option>
<option value = "b">TV advertising</option>
<option value = "c">Phone directory</option>
<option value = "d">Word of mouth</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Order" /></td>
</tr>
</table>
</form>
</body>
</html>

2: processorder.php

<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 />';

$totalqty = 0;
$totalamount = 0.00;

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo 'Items ordered: '.$totalqty.'<br />';

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

$taxrate = 0.10; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $'.number_format($totalamount,2).'<br />';

?>
</body>
</html>

I don't know what is wrong precisly, but when i open orderform.html in the browser and click the button submit order, all i can see in the new rendered page is the whole script as i wrote above, instead of seeing the results. The same happens in all the other scripts. So I can not do anything.

Could you please tell me where the problem is if any of you knows?

I would appriciate it so much.

Thank you

Strike82

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 9:42 am
by jefffan24
1 questions and 2 statements.

Statement: Put your code in the following format [ php]Your Code Here (without the spaces)[/php ]

1st Question: Are you using a server of local machine that has PHP and Apache installed?

2nd Statement: in your code you have

Code: Select all

 
echo '<p>Your order is as follows: </p>';
echo $tireqty.' tires<br />';
echo $oilqty.' bottles of oil<br />';
echo $sparkqty.' spark plugs<br />';
$parkqty is not a defined variable...you need to define it as follows:

$parkqty = $_POST['parkqty']

Explanation: $parkqty is name of variable $_POST is how you are getting the field, parkqty is the name of the field in your form.

So do that above the echo and it should fix that problem.

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 10:26 am
by Strike82
Hi Jefffan24

i have done as you said, now the script looks like this

<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>';

// create short variables names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST ['oilqty'];
$sparkqty = $_POST ['sparkqty'];

echo '<p>Your order is as follows: </p>';
echo $tireqty.' tires<br />';
echo $oilqty.' bottles of oil<br />';
echo $sparkqty.' spark plugs<br />';

$totalqty = 0;
$totalamount = 0.00;

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo 'Items ordered: '.$totalqty.'<br />';

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

$taxrate = 0.10; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $'.number_format($totalamount,2).'<br />';

?>
</body>
</html>

I still get the same problem.

On my machine i have apache 2.2.9 (Win32), PHP 5.2.11, Mysql 5.1.39, PHPMyAdmin 3.2, and Wordpress.

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 10:43 am
by jefffan24
Ok I've never worked on a local machine, I just know you need the programs, I always work on an external server. Sorry :/

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 11:03 am
by Strike82
Ok

but does the script looks ok to you or do you think there is something wrong?

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 11:40 am
by jefffan24
Um I mean I don't see anything right away, but you would need to trigger some errors if it doesn't end up working, but there is obviously something wrong if it is just showing text and its not b/c of your code.

Once you get the code to run and if it still doesn't work you can do trigger_error(E_ALL); and it will display errors depending on where you put it in your script.

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 12:17 pm
by Strike82
Where do i put trigger_error(E_ALL)? In the script?

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 12:23 pm
by jefffan24
I would first try the end, but if that doesn't work then try moving it around to the middle after a major calculation, stuff like that. Until you narrow down what is causing the problems.

Re: Help please. Can not display correctly the script when c

Posted: Sun Nov 08, 2009 12:45 pm
by McInfo
@Strike82: The problem is either with the way the server is configured or how you are accessing the script.

What does the URI look like in your browser's address bar? It should start with "http://" and not "file://".

Where did you save the file? It should be in Apache's document root.

Edit: This post was recovered from search engine cache.

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 2:15 pm
by Strike82
@McInfo

the URI looks like this: file:///C:/htdocs/PHP%20and%20MySQLWebDev/Chapter%2001/processorder.php

the files are saved in the Server document root

Maybe the Server is not configured correctly but i have followed meticoulosly all the steps stated in the book.

The main changes in the php.ini and httpd.conf are as follows:

PHP 5.2.11

php.ini settings

; - Show all errors except for notices and coding standards warnings
;
error_reporting = E_ALL

display_errors = On

log_errors = Off

extension_dir = "C:\php\ext"

upload_tmp_dir = "C:\WINDOWS\Temp"

dynamic extesions added are gd2, imap, mbstring, mysql, mysqli,and xsl.

SMTP = smtp.example.com

sendmail_from = me@example.com

session.save_path = "C:\WINDOWS\Temp"


Apache 2.2.9 openSSL 0.9.8h-r2

httpd.conf settings

LoadModule php5_module C:/php/php5apache2_2.dll

DocumentRoot "C:/htdocs"

<Directory "C:/htdocs">

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

Hope it helps

thanks

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 2:21 pm
by Strike82
@McInfo

Like you said i just noticed that the URI starts with file:// and not http://

So what do i have to do in order to fix this issue and also why is showing like that?

Re: Help please. Can not display correctly the script when c

Posted: Sun Nov 08, 2009 2:24 pm
by McInfo
Go to http://localhost/PHP%20and%20MySQLWebDe ... rform.html and hopefully everything will work.

Also, read PHP Manual: Your first PHP-enabled page.

Edit: This post was recovered from search engine cache.

Re: Help please. Can not display correctly the script when call

Posted: Sun Nov 08, 2009 2:49 pm
by Strike82
@ McInfo

YES mate

it worked!!!

Thanks so much.

I can start my work now.

Keep in touch

Strike82