473,320 Members | 1,883 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,320 software developers and data experts.

Passing values from a multi-select list to a MySQL query using PHP

Hello All,

Can someone help me with a problem I am having? I have a form which
has a multi-select list where the user can select more than one
company name from a list and I need to pass those selections to a
MySQL query for a report. The form is created in PHP.
How do I get the list of items passed to my new page and include
those
in my MySQL statement?
Any and all help is appreciated.
Thanks,
~John
Jun 27 '08 #1
4 3440
John wrote:
Hello All,

Can someone help me with a problem I am having? I have a form which
has a multi-select list where the user can select more than one
company name from a list and I need to pass those selections to a
MySQL query for a report. The form is created in PHP.
How do I get the list of items passed to my new page and include
those
in my MySQL statement?
Any and all help is appreciated.
Try googling for (you'll kick youself when you read the next line):

php multi select


Jun 27 '08 #2
NC
On Jun 8, 2:49*pm, John <john.conk...@cox.netwrote:
>
I have a form which has a multi-select list where the user
can select more than one company name from a list and I need
to pass those selections to a MySQL query for a report. *
The form is created in PHP.

How do I get the list of items passed to my new page and
include those in my MySQL statement?
Give the multi-select a name ending with "[]". Say, you
called it "myMultiSelect[]". Then, when your form is
submitted, all values selected will be members in either
$_GET['myMultiSelect'] or $_POST['myMultiSelect'] array,
depending on the HTTP method used to submit the form.

As to inclusion into SQL statements, you can use implode():

$query = "SELECT stuff FROM theTable WHERE id IN ('"
. implode("', '", $_POST['myMultiSelect'])
. "')";

or foreach(), depending on what you want to do with
inputs received...

Cheers,
NC
Jun 27 '08 #3
On Jun 8, 3:28*pm, NC <n...@iname.comwrote:
On Jun 8, 2:49*pm, John <john.conk...@cox.netwrote:
I have a form which has a multi-select list where the user
can select more than one company name from a list and I need
to pass those selections to a MySQL query for a report. *
The form is created in PHP.
How do I get the list of items passed to my new page and
include those in my MySQL statement?

Give the multi-select a name ending with "[]". *Say, you
called it "myMultiSelect[]". *Then, when your form is
submitted, all values selected will be members in either
$_GET['myMultiSelect'] or $_POST['myMultiSelect'] array,
depending on the HTTP method used to submit the form.

As to inclusion into SQL statements, you can use implode():

$query = "SELECT stuff FROM theTable WHERE id IN ('"
* . implode("', '", $_POST['myMultiSelect'])
* . "')";

or foreach(), depending on what you want to do with
inputs received...

Cheers,
NC
NC,

I just saw your post as I was answering another, and this is exactly
what I needed.

Thank you so much for your reponse...you rock!!

~John
Jun 27 '08 #4
Greetings, John.
In reply to Your message dated Monday, June 9, 2008, 03:27:53,
I have a form which has a multi-select list where the user
can select more than one company name from a list and I need
to pass those selections to a MySQL query for a report. *
The form is created in PHP.
How do I get the list of items passed to my new page and
include those in my MySQL statement?

Give the multi-select a name ending with "[]". *Say, you
called it "myMultiSelect[]". *Then, when your form is
submitted, all values selected will be members in either
$_GET['myMultiSelect'] or $_POST['myMultiSelect'] array,
depending on the HTTP method used to submit the form.

As to inclusion into SQL statements, you can use implode():

$query = "SELECT stuff FROM theTable WHERE id IN ('"
* . implode("', '", $_POST['myMultiSelect'])
* . "')";

or foreach(), depending on what you want to do with
inputs received...
I just saw your post as I was answering another, and this is exactly
what I needed.
Thank you so much for your reponse...you rock!!
I hope you are wise enough to not follow the suggestion showed above...
It is a typical example of SQL injection, waiting to happen.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 27 '08 #5

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

Similar topics

5
by: harry | last post by:
I have 2 multi-dim arrays double subTotals = null; String rowTitles = null; I want to pass them to a function that initialises & populates them like so - loadData( rowTitles, subTotals);
2
by: John Leslie | last post by:
I am porting a script from Korn Shell to python and want to pass named parameters like -JOB 123456 -DIR mydir I can get it to work passing --JOB and --DIR but not -JOB and -DIR Any ideas? ...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
2
by: craigkenisston | last post by:
Hi, I created an array of objects like this : object Values = {myObject.myprop, otherobject.otherprop, thirdobject.xprop}; Then I pass it to a method. and I get the values filled in that...
3
by: SQLScott | last post by:
I have looked all over and I cannot find an example or information on passing a multi-dimensional array. Well, that is not true. I found a close example in C++ but it didn't work when I...
0
by: Kaimar Seljamäe | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
3
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.