select2

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
eptastro
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Feb 02, 2018 9:08 am

Fri Feb 02, 2018 9:29 am

Hi,

I've got a file where the user can select multiple values. When the user submits the form, those values are stored in a mysql database. Each value is a record. This works fine. What I can't make it work is when I retrieve those values from the database and try to display then into the select box so the user can edit them and store them again into the database.

This is how I store the values:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$tournamentid = $_POST[tournamentid];

$field_values_array = array (
'contest' => $_REQUEST['contest']
);

$mysql_rows = [];

foreach($field_values_array['contest'] as $memberid => $item) {
//here $memberid = 8, 3 etc, $item is array

foreach($item as $subItem) {
//here $subItem is FREE50, FREE100 etc
array_push($mysql_rows, [$memberid, $subItem]);
mysql_query("INSERT INTO participations (tournament,member,contest) VALUES ('$tournamentid','$memberid','$subItem')");
}
}

}

and the select box is:

<select multiple name='contest[$mid][]' class='e1' style='width:100%'>
<option value='test1'>test1</option>
<option value='test2'>test2</option>
<option value='test3'>test3</option>
<option value='test4'>test4</option>
<option value='test5'>test5</option>
<option value='test6'>test6</option>
<option value='test7'>test7</option>
</select>

I would be really appreciated if someone could help me.
Thanks in advance

chorn
php-forum Fan User
php-forum Fan User
Posts: 559
Joined: Fri Apr 01, 2016 2:18 am

Mon Feb 05, 2018 2:09 am

i don't see you reading anything from the database, no SELECT statement. also you should consider switching to mysqli or PDO, the msql-functions you use will not work in newer versions of PHP.

Post Reply