I have a form with a field multiple select
:
<form action="processa-chose.php" method="post">
<select id="selecionar" name="fornecedor[]"
data-placeholder="Fabricantes"
style="width:350px;"
multiple class="chosen-select" tabindex="8">
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
<option>XXX</option>
</select>
<input type="submit" value="envie" />
And I want to select the data belonging to the array in the vendor column of the table and then bring the column with the IDs.
I tried this script and it did not work:
<?php
$conect = mysqli_connect("localhost","root","","XXXXXXXXX");
$fornecedor = $_POST['fornecedor'];
$dados = implode(",",$fornecedor);
$sql = "SELECT * FROM fornecedores WHERE fornecedor IN ('$dados')";
$result = mysqli_query($conect,$sql);
while($row = mysqli_fetch_assoc($result)){
echo $row["id"];
}
?>
This is the table:
CREATE TABLE IF NOT EXISTS 'fornecedores' (
'id' int(10) NOT NULL AUTO_INCREMENT,
'fornecedor' varchar(100) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
-- Extraindo dados da tabela 'fornecedores'
--
INSERT INTO 'fornecedores' ('id', 'fornecedor') VALUES
(1, 'XXX'),
(2, 'XXX'),
(3, 'XXX'),
(4, 'XXX'),
(5, 'XXX'),
(6, 'XXX'),
(7, 'XXX'),
(8, 'XXX');