Form Problem help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
greeneel
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:19 pm

Form Problem help

Post 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...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
greeneel
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:19 pm

Post by greeneel »

Im using php 4.0.4pl
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Try this:

Code: Select all

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

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

Tim
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what's that good for?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

obviously nothing.
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post 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.
User avatar
greeneel
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:19 pm

Post by greeneel »

ok tsg the

."\t" . "$address" . "\n"; worked just fine thx man...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

spooky ;)
Post Reply