943,965 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 14903
  • PHP RSS
Feb 19th, 2005
0

HTML Select and PHP 5 - Issue

Expand Post »
My simple HTML script below uses SELECT to create a list which should be accessed by the PHP script as an array. Note the products[] definition below.
BUT.... I can't seem to get the script to read the array from $_POST['products'] - anyone know how to solve this?


<HTML>
<TITLE>Input Form2</TITLE>
<FORM method="POST" action="FormRead2.php">
<BR>Name:<BR>
<INPUT type="text" name="user">
<BR>Address:<BR>
<TEXTAREA name="address" rows="5" cols="40">
</TEXTAREA>
<BR>Products:<BR>
<SELECT name "products[]" multiple>
<option>SFone
<option>CTI Desktop
<option>Real-Time Monitor
</SELECT>
<BR>
<INPUT type="submit" name="submit" value="Submit">
</FORM>
</HTML>


And here is the simple PHP script:


<HTML>
<TITLE>Action Script for InputForm2</TITLE>
<?php
if(isset($_POST['submit'])) {
echo "Welcome <b>".$_POST['user']."</b><P>\n\n";
echo "Your address is:<P>\n\n<b>".$_POST['address']."</b><p>\n\n";
echo "Your product choices are:<p>\n\n";
echo "<UL>\n\n";

foreach($_POST['products'] as $value) {
echo "<LI>$value<BR>\n";
}

echo "</UL>";
}
?>
</HTML>
Similar Threads
Reputation Points: 10
Solved Threads: 3
Light Poster
mcldev is offline Offline
31 posts
since Feb 2005
Feb 20th, 2005
0

Re: HTML Select and PHP 5 - Issue

Quote originally posted by mcldev ...

<option>SFone</option>
<option>CTI Desktop</option>
<option>Real-Time Monitor</option>
I don't really care to connect to a server to try this out, but even if this doesn't fix the problem, you should always use closing tags. Even <br> tags are now <br /> tags, for instance.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
rice_web is offline Offline
11 posts
since Jul 2004
Feb 21st, 2005
0

Re: HTML Select and PHP 5 - Issue

The Solution

In case you are interested, the key to getting the HMTL script to pass SELECT data is to 1) declare your variable as an array, i.e. use brackets like product[], 2) Then in your PHP action script make sure you treat product as an associative array, i.e. forech($_POST['product'] as $key=>$value). Note, this allows you to pass over multiple selections.

Also, note the use of _POST. If you are still using PHP4 it is important to look at _SERVER, _GET, etc. because you will undoubtly cross their path during forms development. You can use the long names like HTTP_POST_VARS but the shorter names are more managable.
Reputation Points: 10
Solved Threads: 3
Light Poster
mcldev is offline Offline
31 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP File Searching
Next Thread in PHP Forum Timeline: Help Me In Font Conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC