954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HTML Select and PHP 5 - Issue

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?

Input Form2

Name:

Address:

Products:
SFone
CTI Desktop
Real-Time Monitor

mcldev
Light Poster
31 posts since Feb 2005
Reputation Points: 10
Solved Threads: 3
 
SFoneCTI DesktopReal-Time Monitor

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
tags are now
tags, for instance.

rice_web
Newbie Poster
11 posts since Jul 2004
Reputation Points: 10
Solved Threads: 1
 

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.

mcldev
Light Poster
31 posts since Feb 2005
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You