I have a select dropdown in html but it won't select multiple values. here is the code that I have for this:
<div class="col-sm-10">
<select multiple id="cmbService" name="cmbService" class="form-control" >
<option value="0">- Select One -</option>
<?php
try{
$dbHost = "localhost";
$dbUser = "mdchadmin";
$dbPass = "123456";
$dbName = "mdch_new";
$conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT PROMO_NUMBER, PROMO_NAME FROM PROMOS where status=1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<option value=\"{$row['PROMO_NUMBER']}\">{$row['PROMO_NAME']}</option>";
}
}
$conn->close();
}catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
</select>
</div>
EDIT: IT NOW WORKS THANKS TO THE ANSWER. BUT NOW I HAVE A NEW PROBLEM(kinda) and i'm going thru this
so i did what u suggested, and im getting this $customer array in my other php file which results to:
te,GIAN MARCO.'_'.1235
g,g.'_'.123
where 1235 and 123 are the data on the mobile numbers column.
the problem is , when i do
$mobile=(explode("_",$customers));
it doesn't give me anything when i output it via:
foreach($mobile as $z) {
echo $z; echo "<br>";}
@identity unknown
You simply need to add an square bracket in your name
attribute name="cmbService[]"
<select id="cmbService" name="cmbService[]" class="form-control multiple " >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With