Problem in Select Multiple Form

1

I'm having trouble receiving multiple choices and inserting into MySQL

I created this script sequence but

<form method="post" action="01maxtestes.php">
<select name="padroes" size="10" multiple>

<?
    do  
      {

?>
        <option value="<? echo $MAXI_pad_select['PAD_ID']; ?>"><? echo $MAXI_pad_select['PAD_NUM_CERTIFICADO']; ?> - <? echo $MAXI_pad_select['PAD_IDENTI']; ?> - <? if($MAXI_pad_select['PAD_STATUS_VALIDA'] == 0){ echo "<strong>(VALIDO) </strong>"; }elseif($MAXI_pad_select['PAD_STATUS_VALIDA'] == 1){ echo "(H&Aacute; VENCER)"; }else{ echo "(VENCIDO)"; } ?></option>

<? }while($MAXI_pad_select = mysql_fetch_assoc($MAXI_pad_select_query));
?>

</select>
<br /><br />
<input type="submit" value="Enviar" />
<input type="reset" value="Cancelar" />
</form>

Then when you send it it receives only a number through it

$padroes_testesss = $_POST['padroes'];

But if I select more than one it only returns the last selected information. only I want it to return 1 or more selected information in the list by linking to an Insert Into from another table.

Can anyone give me strength?

I'm using PHP 5.4.

    
asked by anonymous 02.04.2017 / 21:54

1 answer

0

The name of your select has to be standard []

<select name="padroes[]" size="10" multiple>

This will send an array of the selected values.

To recover these values and insert into the DB do as follows:

if (isset($_POST["padroes"])) {
    $optionArray = $_POST["padroes"];
    for ($i = 0; $i < count($optionArray); $i++) {
        $todos=$todos.",".$optionArray[$i];
    }
}

$todos=substr($todos, 0, -1);
$aDest = explode(",", $todos);

("Insert into TABELA (coluna1,coluna2,coluna3 .......) 
  values ('".$aDest[0]."','".$aDest[1]."','".$aDest[2]."',.......
    
02.04.2017 / 23:57