Handling data from multiple select field

Asked
Active3 hr before
Viewed126 times

7 Answers

selectmultiple
90%

It's also worth noting that the string approach can be safely and successfully used for numeric values as well, because MySQL will also convert the values to the correct type. But in general it is better and more efficient to pass the data in with the correct type representation within the query.,My interest is to get the deduction values to an array and store it in db in this manner: value1,value2,value3. Unfortunately I have not been able to achieve this.Instead only a single value of the intended array is obtained. Your assistance will be highly appreciated.Thanks.,Next let's take a look at what is wrong with the previous answer. This centres around escaping user input. It uses mysql_real_escape_string() is a way that really makes no sense whatsoever. This should be used for escaping a single string literal, and absolutely nothing else, ever. It cannot be used to effectively escape numbers, and it cannot be used to escaped parts of SQL that are not only values.,But often in this scenario, the values would simply be numbers, and in this case all we need to do is ensure that PHP is representing them with the correct data type, since they will be automatically safe when they are converted back to strings to be used in the query:

Here's what we would do if the values are strings (usually a CHAR or VARCHAR field):

// First create an array of individually escaped values with quotes added
$deds = array();
foreach($_POST['deductions'] as $ded) {
   $deds[] = "'".mysql_real_escape_string($ded).
   "'";
}

// Now join them together in an SQL syntax
$deds_joined = join('), (', $deds);

// Now they can safely be used in the query
$query = "INSERT INTO mytable (deduction) VALUES ($deds_joined)";

But often in this scenario, the values would simply be numbers, and in this case all we need to do is ensure that PHP is representing them with the correct data type, since they will be automatically safe when they are converted back to strings to be used in the query:

// First convert the array values to integers
$deds = array();
foreach($_POST['deductions'] as $ded) {
   $deds[] = (int) $ded;
}

// Now join them together in an SQL syntax
$deds_joined = join('), (', $deds);

// Now they can safely be used in the query
$query = "INSERT INTO mytable (deduction) VALUES ($deds_joined)";
load more v
88%

For window users – hold down + CTRL key to select multiple option,How to get multiple selected values of select box in php?,For mac users – hold down command key to select multiple option,How to Select Multiple Files using HTML Input Tag ?

72%

A drop-down list that allows multiple selections:,For windows: Hold down the control (ctrl) button to select multiple options,For Mac: Hold down the command button to select multiple options,When present, it specifies that multiple options can be selected at once.

Definition and Usage

The multiple attribute is a boolean attribute.

multiple
65%

There are several form controls used to allow the user to select input from a group of options. For example, list box and checkbox.,By default, we can select multiple options from a group of checkboxes. But for list box control, a multi-select option is not provided by default. And, we should set MULTIPLE properties with SELECT tag. For setting MULTIPLE properties, we can use both of the following ways.,In this PHP example program, we have a list box control with a set of languages. It will be loaded dynamically from a MySQL table. And the code for loading this multi-select box is,, <select name="multiSelect" multiple> ... </select>

<select name="multiSelect" multiple="multiple">
   ...
</select>
load more v
75%

We can select the multiple options in the dropdown list using the multiple attribute. There are several ways in JavaScript to return the selected values in a multi-select dropdown.,The idea is to iterate over all dropdown options using the for…of statement and collect values of all the <option> elements having the selected attribute.,This post will discuss how to get the selected values in a multi-select dropdown in plain JavaScript.,That’s all about getting selected values in a multi-select drop-down with JavaScript.

This post will discuss how to get the selected values in a multi-select dropdown in plain JavaScript.

We can select the multiple options in the dropdown list using the multiple attribute. There are several ways in JavaScript to return the selected values in a multi-select dropdown.

multiple
load more v
40%

For window users – hold down + CTRL key to select multiple option,For mac users – hold down command key to select multiple option,Given a list of items and the task is to retrieve the multiple selected value from a select box using PHP.,Now, the task is to retrieve or print multiple selected value from list. Use form method and loop to retrieve selected value in PHP.

<
html
>
load more v
22%

Multi-select text field properties , Multi-select text field properties ,Convert the copied field to multi-select text., Convert the copied field to multi-select text.

Enter the formula shown below, substituting your checkbox field names for Field 1, Field 2, and so on.

List(";",
load more v

Other "select-multiple" queries related to "Handling data from multiple select field"