Jump to content

[SOLVED] PHP Simple code problem


luke1983

Recommended Posts

Hi All,

I have started to learn PHP and MySQL i have set up Apache 2.2, MySQL and PHP on my PC. i have been learning all this from a book called php and mysql web development. Anyway, the first thing i did was test a simple code form chapter 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>

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>

 

 

But all i get is this as the out come not matter what i fill in on the first page. i even removed the costs sction so the code only echoed the numbers from the orderform.html but still nothing.

 

Bob's Auto Parts

Order Results

Order processed at 18:50, 8th August

 

Your order is as follows:

 

tires

bottles of oil

spark plugs

Items ordered: 0

Subtotal: $0.00

Total including tax: $0.00

 

Any help would be great as i am on chapter one and i am stuck already.

 

thanks luke

Link to comment
https://forums.phpfreaks.com/topic/169379-solved-php-simple-code-problem/
Share on other sites

In your processorder.php file, you need to assign the values you are POSTing. In other words, since you used a POST action on your original form, you need to retrieve those values on the processorder.php script. Do this by taking the name attribute from each of your input fields in the form like so:

 

$tireqty = $_POST['tireqty'];

 

and do that for all your input values

Archived

This topic is now archived and is closed to further replies.

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