I want a user to choose values from the Multiple Select box: - <select name="service[]" id="service" size="6" multiple="multiple">
-
<option value="histopathology">Histopathology</option>
-
<option value="cytology">Cytology</option>
-
<option value="endometrial biopsy">Endometrial Biopsy</option>
-
<option value="joint fluid">Joint Fluid</option>
-
<option value="bone marrow">Bone Marrow</option>
-
<option value="other">Other</option>
-
</select>
the table is: - services CREATE TABLE `services` (
-
`service_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-
`form_number` int(20) NOT NULL,
-
`histo` tinyint(1) DEFAULT NULL,
-
`cytology` tinyint(1) DEFAULT NULL,
-
`endo` tinyint(1) DEFAULT NULL,
-
`joint_fluid` tinyint(1) DEFAULT NULL,
-
`bone_marrow` tinyint(1) DEFAULT NULL,
-
`other` varchar(50) DEFAULT NULL,
-
PRIMARY KEY (`service_id`)
-
) ENGINE=MyISAM DEFAULT CHARSET=latin1
im not sure how to insert the information as one record with the selections they choose.
Hey.
When you submit a select like that, the selected options are available in your PHP code as an array, found in the $_POST super-global. Like in your code, if I were to select "histopathology" and "other", PHP would make those choices available in this format: - $_POST => Array
-
(
-
[service] => Array
-
(
-
[0] => histopathology
-
[1] => other
-
)
-
-
)
-
So to figure out which choices were selected, you simple check if the choice exists in that array. To do that, you can use the in_array function. - $fieldExists = in_array("fieldName", $_POST['service']);
Then you use that to build your query. For example: - // Create the top of the SQL query
-
$sql = "INSRT INTO `services` SET\n";
-
-
// Find out which choices were selected.
-
$data = array(
-
'histo' => in_array('histopathology', $_POST['service']),
-
'cytology' => in_array('cytology', $_POST['service']),
-
'endo' => in_array('endometrial biopsy', $_POST['service']),
-
'joint_fluid' => in_array('joint fluid', $_POST['service']),
-
'bone_marrow' => in_array('bone marrow', $_POST['service']),
-
'other' => in_array('other', $_POST['service']),
-
);
-
-
// Add each option to the SQL query.
-
foreach($data as $_fieldName => $_fieldValue) {
-
$_fieldValue = $_fieldValue ? "TRUE" : "FALSE";
-
$sql .= " `{$_fieldName}` = $_fieldValue\n";
-
}
-
-
// Echo the query
-
echo $sql;
This might print something like: - INSRT INTO `services` SET
-
`histo` = FALSE
-
`cytology` = TRUE
-
`endo` = FALSE
-
`joint_fluid` = TRUE
-
`bone_marrow` = FALSE
-
`other` = TRUE
2 2926 Atli 5,058
Expert 4TB
Hey.
When you submit a select like that, the selected options are available in your PHP code as an array, found in the $_POST super-global. Like in your code, if I were to select "histopathology" and "other", PHP would make those choices available in this format: - $_POST => Array
-
(
-
[service] => Array
-
(
-
[0] => histopathology
-
[1] => other
-
)
-
-
)
-
So to figure out which choices were selected, you simple check if the choice exists in that array. To do that, you can use the in_array function. - $fieldExists = in_array("fieldName", $_POST['service']);
Then you use that to build your query. For example: - // Create the top of the SQL query
-
$sql = "INSRT INTO `services` SET\n";
-
-
// Find out which choices were selected.
-
$data = array(
-
'histo' => in_array('histopathology', $_POST['service']),
-
'cytology' => in_array('cytology', $_POST['service']),
-
'endo' => in_array('endometrial biopsy', $_POST['service']),
-
'joint_fluid' => in_array('joint fluid', $_POST['service']),
-
'bone_marrow' => in_array('bone marrow', $_POST['service']),
-
'other' => in_array('other', $_POST['service']),
-
);
-
-
// Add each option to the SQL query.
-
foreach($data as $_fieldName => $_fieldValue) {
-
$_fieldValue = $_fieldValue ? "TRUE" : "FALSE";
-
$sql .= " `{$_fieldName}` = $_fieldValue\n";
-
}
-
-
// Echo the query
-
echo $sql;
This might print something like: - INSRT INTO `services` SET
-
`histo` = FALSE
-
`cytology` = TRUE
-
`endo` = FALSE
-
`joint_fluid` = TRUE
-
`bone_marrow` = FALSE
-
`other` = TRUE
thanks so much for your reply...it helps out for my project...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: murraymiken |
last post by:
I'm looking to have multiple multiple-select-boxes on a page. But I
can only get the contents from the last selected value within a box,
via PHP. I've tried numerous methods.
What am I doing...
|
by: abhishekhs |
last post by:
Hi all
I have more than one multiple select lists in a page. Something like this
<tr>
<td>
<select NAME="StrainList" ID="StrainList" SIZE="5" multiple="multiple" style="width: 150px">
<?...
|
by: scott |
last post by:
Hello all,
I am ripping my hair out over this and maybe someone could help.
I have a site that has groups and subgroups of those groups that all
have int id's.
I am trying to have a...
|
by: ozzii |
last post by:
Hi
I have a HTML form with a multiple select box. The multiple select box is populated from a database. A user can select multiple options form this select box and the infomrtaion is then stored...
|
by: sundsx |
last post by:
Hi, i would sen multiple select to mysql by form, my prb is:
file connect.php
<?php
$user="sundsx";
$pass="password";
$db="testphp";
$val_form=$_POST;
$service =$_POST;
|
by: sathyashrayan |
last post by:
Dear group,
I have a task where I have to fetch datas from mysql and display it
in the multiple select list box. I have fetched the datas and it is
getting diplayed correctly in the multiple...
|
by: =?Utf-8?B?VGVycnk=?= |
last post by:
I have coded multiple select statements in a single stored procedure, and
when I execute this procedure on SQL Server Management Express, I correctly
get multiple result sets. But, if I try to add...
|
by: fishctr |
last post by:
Hi There,
I am creating a survey that asks users what countries they have worked in, and which regions in those countries. Because there can be many answers, I was thinking I could populate a...
|
by: bonneylake |
last post by:
Hey Everyone,
Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section.
...
|
by: phpnewbie26 |
last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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...
|
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....
|
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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |