0
Good morning.
I’m making a INSERT
in the bank via PHP
, with data coming from a SELECT MULTIPLE
. The data of this SELECT
comes from a bank table:
HTML:
<select name="numerosdasorte[]" class="form-control" multiple="">
<?php
$consulta = $PDO->query("SELECT * FROM cota1 ORDER BY cota ASC");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
?>
<option value="<?php echo $linha['cota']; ?>"><?php echo $linha['cota']; ?></option>
<?php } ?>
</select>
When do I perform the SUBMIT
of FORM
, take the variable and place the commas to separate the chosen numbers:
PHP:
$numerosdasorte = '';
foreach($_POST['numerosdasorte'] as $numeros){
$numerosdasorte .= ',' . $numeros;
}
$numerosdasorte = ltrim($numerosdasorte, ',');
The code works normally, saved in the bank exactly the way I want it. The question is this: I need to separate these numbers to do the UPDATE
on the table cota1
, so that, when entering again, they are unavailable. In the table, I set as BOOLEAN
, so I need to do this UPDATE
to make the number unavailable for the next registration.
Anyway, I can’t think of a way to do that. A friend suggested making a UPDATE
before FORM
be submitted, in the choice of number. But, if the person gives up the registration, the number will be unavailable, even if the FORM
is not submitted.
I think if I can separate those numbers, I can do the UPDATE
of each of them in the table. What do you think?
I would like the justification of "downvote", to know where I am going wrong. For me, it is a doubt. I think every downvote should have mandatory justification.
– Hebert Richard Masseno Dias
you want to separate these numbers into an array? being each number in 1 position?
– Arthur Luiz
Arthur, thank you for your time. I think it would be easier to update the table of numbers in the bank. Unless you have another way, I’d like your opinion, please,
– Hebert Richard Masseno Dias