Page 1 of 1

Form Problem help

Posted: Mon Aug 25, 2003 2:16 am
by greeneel
Hi All,

I am having problems with the following form when I enter and address into the address field it doesn`t output to the processorder page. here are the codes can anyone help?

The form:

Code: Select all

<html>
<head>
  <title>Hazels Garage</title>
</head>
<body>
<h1>Hazels Garage</h1>
<h2>Order Form</h2>

<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=left><input type="text" name="tireqty" size=3 maxlength=3></td>
</tr>
<tr>
  <td>Oil</td>
  <td align=left><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
  <td>Spark Plugs</td>
  <td align=left><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
  <td>Shipping Address</td>
  <td align=center><input type="text" name="address" size=40 maxlength=40></td>
</tr>
<tr>
  <td colspan=2 align=center><input type=submit value="Submit Order"></td>
</tr>
</table>
</form>  

</body>
</html>
The process order page:

Code: Select all

<html>
<head>
  <title>Hazels Garage - Order Results</title>
</head>
<body>
<h1>Hazels Garage</h1>
<h2>Order Results</h2>
<? 
  $totalqty = 0;
  $totalqty += $tyreqty;
  $totalqty += $oilqty;
  $totalqty += $sparkqty;
  
  $totalamount = 0.00;
 
  define("TYREPRICE", 100);
  define("OILPRICE", 10);
  define("SPARKPRICE", 4);

  $date = date("H:i, jS F");
 
  echo "<p>Order processed at ";
  echo $date;
  echo "<br>";
  echo "<p>Your order is as follows:";
  echo "<br>";

  if( $totalqty == 0 )
  {
    echo "You did not order anything on the previous page!<br>";
  }
  else
  {
    if ( $tyreqty>0 )
      echo $tyreqty." tyres<br>";
    if ( $oilqty>0 )
      echo $oilqty." bottles of oil<br>";
    if ( $sparkqty>0 )
      echo $sparkqty." spark plugs<br>";
  }

  $total = $tyreqty * TYREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; 
  $total=number_format($total, 2, ".", " ");
 
  echo "<P>Total of order is ".$total."</p>";
  
  echo "<P>Address to ship to is ".$address."<br>";

  $outputstring = $date."\t".$tyreqty." tyres \t".$oilqty." oil\t"
                  .$sparkqty." spark plugs\t\$".$total
                  ."\t". $address."\n";

  // open file for appending
@ $fp = fopen("../../orders/orders.txt", "a");

  flock($fp, 2); 
 
  if (!$fp)
  {
    echo "<p><strong> Your order could not be processed at this time.  "
         ."Please try again later.</strong></p></body></html>";
    exit;
  } 

  fwrite($fp, $outputstring);
  flock($fp, 3); 
  fclose($fp);

  echo "<p>Order written.</p>"; 

?>
</body>
</html>
mod_edit: added code and php tags

everything else works ok when submitted but its only the Address field that when i enter text mnothing echos to the processorder.php page...

Posted: Mon Aug 25, 2003 9:27 am
by volka
are you sure everything else is ok?
If I use extract() to emulate register_globals your script works fine.
Which version of php do you use?
Maybe Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+ will help

Posted: Mon Aug 25, 2003 4:46 pm
by greeneel
Im using php 4.0.4pl

Posted: Mon Aug 25, 2003 9:21 pm
by tsg
Try this:

Code: Select all

// instead of 
."\t". $address."\n"; 

// try
."\t" . "$address" . "\n";
add the quotes around it.

Tim

Posted: Mon Aug 25, 2003 9:29 pm
by volka
what's that good for?

Posted: Mon Aug 25, 2003 9:30 pm
by tsg
obviously nothing.

Posted: Mon Aug 25, 2003 9:34 pm
by tsg
well, I look again, and maybe it is good because he is joing with the dots ... and because the adderss will have spaces and not being treated as a numerical value, it should be quoted .. at least that's how I would do it.

Maybe it will work, maybe not .. just a suggestion.

Posted: Mon Aug 25, 2003 11:00 pm
by greeneel
ok tsg the

."\t" . "$address" . "\n"; worked just fine thx man...

Posted: Mon Aug 25, 2003 11:02 pm
by volka
spooky ;)