help starting php
Posted by: spillage (82.152.153.---)
Date: March 18, 2008 10:36PM

just starting out in php and all is new. i am following all the right things in a idiots guide book but when i submit info from a form the php file will not run properly and am asked if i want to run open or cancel. its just like the php server is just not running. i havnt changed any settings and all the code works in phpdesigner so i know its all right. any help would be appreciated.

Options: ReplyQuote
Re: help starting php
Posted by: spillage (82.152.153.---)
Date: March 18, 2008 10:46PM

just to let you know if i run the php file through local host its fine. its just when running the html file the php file will not start. :-(

Options: ReplyQuote
Re: help starting php
Posted by: yfastud (Moderator)
Date: March 19, 2008 02:03AM

All files has to run through localhost so apache can parse php codes; html file w/ including php scripts must be saved as php files

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: help starting php
Posted by: spillage (---.demon.co.uk)
Date: March 19, 2008 12:05PM

All the files are in the www folder here is the code of both html and php files I am running. Open the html and fill it out and on submit all I get is a page of php code. The php file will not run. If run through my php designer it works though????

ORDER FORM

<html>
<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>

PHP FILE

<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$find = $_POST['find'];
?>
<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>';

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

if( $totalqty == 0)
{
echo 'You did not order anything on the previous page!<br />';
}
else
{
if ( $tireqty>0 )
echo $tireqty.' tires<br />';
if ( $oilqty>0 )
echo $oilqty.' bottles of oil<br />';
if ( $sparkqty>0 )
echo $sparkqty.' spark plugs<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 />';


if($find == 'a')
echo '<p>Regular customer.</p>';
elseif($find == 'b')
echo '<p>Customer referred by TV advert.</p>';
elseif($find == 'c')
echo '<p>Customer referred by phone directory.</p>';
elseif($find == 'd')
echo '<p>Customer referred by word of mouth.</p>';
else
echo '<p>We do not know how this customer found us.</p>';


?>
</body>
</html>

Options: ReplyQuote
Re: help starting php
Posted by: spillage (---.demon.co.uk)
Date: March 19, 2008 12:44PM

ok confession time. the form action should have been "http//localhost/processorder.php" not "processorder.php"

now im going to fine a dark hole to hide in and get drunk

thanks.

Options: ReplyQuote
Re: help starting php
Posted by: toivo (203.19.130.---)
Date: March 19, 2008 12:58PM

Hi,

If order.html file containing your code is run in working WAMP5 system, the form is POSTed to the processorder.php script and it outputs the HTML page all right.

Have you modified the default settings in any way?

You could try to create the file phpinfo.php with the following contents:

<?php
phpinfo();
?>

When you run it, it should present the PHP settings nicely formatted.

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: help starting php
Posted by: toivo (203.19.130.---)
Date: March 19, 2008 01:44PM

Hi Spillage,

I just saw your last message: No need to go and hide.

The action "processorder.php" works fine, the default location for files is the current working directory and you do not have to include the full path or URL. Using a relative path should work all right and makes it easier to migrate your code to a different server environment.

Regards,

toivo
Sydney, Australia

Options: ReplyQuote


Sorry, only registered users may post in this forum.