473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

simple php queston

I have a multi select pick list in an html

<FORM ACTION="/progs/read.php" METHOD="POST" target="_blank">^M

<label for="CATEGORIES">Select one or more categories</label>^M
<SELECT MULTIPLE name="CATEGORIES" size="10" id="CATEGORIES"
class="select">
<option value="41">Auto Manufacturers</option>
<option value="27">Biodiesel</option>
<option value="38">Component Suppliers</option>
<option value="39">Conversion Companies</option>
<option value="40">Dealers</option>
<option value="28">Electricity</option>
</select>

in read.php i try to read the value by:

$categories=htmlspecialchars($_POST['CATEGORIES']);
then try to print out the value and all I get is the last value.
I tried to put in an array like:

$categories=array($_POST['CATEGORIES']);

and still got the same result.

What am I doing wrong?

Thank you
Jun 5 '07 #1
3 1258
Mark Winter wrote:
<SELECT MULTIPLE name="CATEGORIES" size="10" id="CATEGORIES"
[...]
$categories=htmlspecialchars($_POST['CATEGORIES']);
You need to turn that into an array. Keep in mind that a <select multiple>
returns several GET or POST variables with the same name. So, you'll have
to use the magic of the [] operator here:

<select multiple='multiple' name='categories[]' ... >

And then, something like:

foreach($_POST['categories'] as $cat)
{
echo $cat;
}

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

You will be awarded a medal for disregarding safety in saving someone.

Jun 5 '07 #2
Iván Sánchez Ortega wrote:
Mark Winter wrote:
> <SELECT MULTIPLE name="CATEGORIES" size="10" id="CATEGORIES"
[...]
>$categories=htmlspecialchars($_POST['CATEGORIES']);

You need to turn that into an array. Keep in mind that a <select multiple>
returns several GET or POST variables with the same name. So, you'll have
to use the magic of the [] operator here:

<select multiple='multiple' name='categories[]' ... >

And then, something like:

foreach($_POST['categories'] as $cat)
{
echo $cat;
}
if you just want to get the entries as a string to store in the database
and don't want to display them straight away, you could do the following
and not have to recurse through the array:

$categories = (string)@implode(",", $_POST['categories']));

Jun 8 '07 #3
Tyno Gendo wrote:
Iván Sánchez Ortega wrote:
>Mark Winter wrote:
>> <SELECT MULTIPLE name="CATEGORIES" size="10" id="CATEGORIES"
[...]
>>$categories=htmlspecialchars($_POST['CATEGORIES']);

You need to turn that into an array. Keep in mind that a <select
multiple>
returns several GET or POST variables with the same name. So, you'll have
to use the magic of the [] operator here:

<select multiple='multiple' name='categories[]' ... >

And then, something like:

foreach($_POST['categories'] as $cat)
{
echo $cat;
}

if you just want to get the entries as a string to store in the database
and don't want to display them straight away, you could do the following
and not have to recurse through the array:

$categories = (string)@implode(",", $_POST['categories']));
That would be against normalization techniques, and this type of setup
will cause problems later.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: delisonews | last post by:
I'm looking for a simple, filesystem-based message board. (No MySQL!) Something that I could include easily in my code: include '../inc/messageboard.php'; .... so that the board shows up at...
3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
8
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
6
by: Manuel Collado | last post by:
I would like to write simple, yet well structured documents with a really simple XML DTD (or schema). Either Docbook or SDocbook are overkill for this simple case. XHTML is simpler, but...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
13
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.