Current location: Hot Scripts Forums » Programming Languages » PHP » Form field values don't show in my browser


Form field values don't show in my browser

Reply
  #1 (permalink)  
Old 10-18-03, 07:32 PM
cstallins's Avatar
cstallins cstallins is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Form field values don't show in my browser

I'm working through a book that many of you may have used, PHP and MySQL Web Development, by Welling and Thomson. Early in the book we create a small form to input values on a bogus auto parts web site, which then are echoed to the browser via a short PHP script. Everything works great except that my form field values do not get echoed. I'm running WinXP and Apache. The following are my HTML form text, followed by the PHP code that is supposed to process the form input. I would appreciate any input as to why the integers I enter in my form fields do not get echoed to the screen via the PHP variables.
Thank you for any advice you can offer.
Curtis

<html><head><title>Bob's Basic Order Form</title></head>
<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 colspan="2" align="center">
<input type="submit" value="Submit Order">
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body></html>


This is my PHP processing script:
<html><head><title>Bob's Auto Parts - Order Results</title></head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?
echo "<p>Order processed at";
echo "<br />";
echo date("g:i a, F jS, Y");
echo "<br /><br />";
echo "<p>Your order is as follows:";
echo "<br />";
echo $tireqty." tires<br />";
echo $oilqty." quarts of oil<br />";
echo $sparkqty." spark plugs</p>";
?>
</body></html>
Reply With Quote
  #2 (permalink)  
Old 10-18-03, 07:44 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
A suggestion...

You have this...

echo $tireqty." tires<br />";
echo $oilqty." quarts of oil<br />";
echo $sparkqty." spark plugs</p>";

Try this...

echo "$tireqty tires<br />";
echo "$oilqty quarts of oil<br />";
echo "$sparkqty spark plugs</p>";

The $blahblah should be inside the " ", and no period. See what happens.
Reply With Quote
  #3 (permalink)  
Old 10-18-03, 08:09 PM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
No, putting it outside the quotes shouldn't matter. Mabe you've got register_globals off, try accessing the variables via the $_POST array.

echo $_POST['tireqty']." tires<br />";
// etc..
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #4 (permalink)  
Old 10-18-03, 08:14 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
I thought whatever you were going to echo had to be inside the quotes...sorry if I was off on that one.
Reply With Quote
  #5 (permalink)  
Old 10-19-03, 01:00 AM
cstallins's Avatar
cstallins cstallins is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Chroder
No, putting it outside the quotes shouldn't matter. Mabe you've got register_globals off, try accessing the variables via the $_POST array:
echo $_POST['tireqty']." tires<br />";
// etc..

I did as you suggest, employing the $_POST text, and my problem is solved. I also tried moving my variables inside the quotes, as another helpful person suggested, but had no success. I have not yet learned about the $_POST array, but I certainly thank you for setting me straight. Interesting, the commented text from the php.ini file says that we should strive to write our code so that we can keep register_globals off. See the cut'npaste from the php.ini file below:

; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off
Reply With Quote
  #6 (permalink)  
Old 10-19-03, 10:32 AM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Red this tut from over at sitepoint: http://www.sitepoint.com/article/758/1
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #7 (permalink)  
Old 10-19-03, 11:12 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
i have that book as well, very good book but a few little things left out.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.NET - Show another form? Tesco Windows .NET Programming 11 06-04-04 07:09 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
passing values from one form to another -urgent aspuser25 ASP 1 09-19-03 06:41 PM
echo in a form field tgarske PHP 2 08-25-03 05:34 PM
asp: values in array not in order?? seala ASP 0 08-16-03 12:06 PM


All times are GMT -5. The time now is 07:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.