Problem on Select Multiple Form

Asked

Viewed 38 times

1

I’m having trouble receiving multiple choices and inserting in 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>

Ai when sending he receives only one number through this

$padroes_testesss = $_POST['padroes'];

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

Someone can give me a strength?

I am using PHP 5.4.

1 answer

0

The name of your select has to be standards[]

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

This way an array of selected values is sent.

To recover these values and insert in DB do so:

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]."',.......

Browser other questions tagged

You are not signed in. Login or sign up in order to post.