Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Learning PHP, need help.
Old 11-02-2004, 12:42 AM Learning PHP, need help.
NJBS-COM's Avatar
Novice Talker

Posts: 10
Trades: 0
I'm learning PHP and i'm having trouble. How would pass the variables from a form with register_globals turned off?

<html>
<body>
<form method=POST Action="listbox.php">
What price of car are you looking for?
<select name="price">
<option>Under $5,000</option>
<option>$5,000-$10,000</option>
<option>$10,000-$25,000</option>
<option>Over $25,000</option>
</select>
<br>
<br>
What size engine would you consider?
<select name="enginesize[]"multiple >
<option>1.0L</option>
<option>1.4L</option>
<option>1.6L</option>
<option>2.0L</option>
</select>
<br>
<br>
<input type=submit value="Enter">
</form>
</body>
</html>
NJBS-COM is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-02-2004, 01:30 AM
foobar's Avatar
Extreme Talker

Posts: 225
Trades: 0
To retrieve the variables in the page specified in the action attribute of your form (in your case, listbox.php) use:

PHP Code:
$_POST['field_name']; 
For a form passed using the POST method, or:

PHP Code:
$_GET['field_name']; 
For a form passed using GET.

In both cases, 'field_name' is the name of the field for which you want to get the value. IN your case, you have two: price and enginesize.

However, if you use the same form you posted, you'll run into problems: notably, no value will ever be passed, since you must specify, in each option tag, the value attribute, which is the value to pass if that specific radio button was selected.

Whereas textboxes (input type="text") pass their contents, for radio buttons and checkboxes, you must specify each controls' value. The text you insert between the start and closing tags are only for display purposes.

Hope that helps.
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-02-2004, 02:09 AM
NJBS-COM's Avatar
Novice Talker

Posts: 10
Trades: 0
Thanks for you help, how would i use the $_POST['field_name']; for the multiple enginesize options?

Code:
<?php

echo $_POST['price'];
echo  dunno what to do here  

?>
NJBS-COM is offline
Reply With Quote
View Public Profile
 
Old 11-03-2004, 08:28 PM
NJBS-COM's Avatar
Novice Talker

Posts: 10
Trades: 0
bump
NJBS-COM is offline
Reply With Quote
View Public Profile
 
Old 11-03-2004, 09:34 PM
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
<select name="enginesize[]"multiple >
.
.
.
</select>

PHP Code:
$sizes $_POST['enginesize']; 
The $sizes will hold an array. You need to use a foreach loop to use the values of the array.

You can print the $sizes array like this...
PHP Code:
print "<pre>";
print_r ($sizes);
print 
"</pre>"
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to Learning PHP, need help.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15319 seconds with 12 queries