how to access values in jquery muiltiselect through php

89 Views Asked by At

I'm using jquery multiselect and in options i'm fetching data from database these are basically available seats in a buss.. when user selected some seats and press the button i'm putting values on $_POST and using update query updating selected seats as reserved please help here is the code

** HTML SELECT tag with jquery and php for fetching data this is working fine **

<form action="" method="post">
    <label for="required">Required</label>
    <select id="required" multiple="multiple" data-placeholder="Select attendees..." name="required">
     <?php 

$con =   mysql_connect("localhost","root","") or die(mysql_error());
$link =      mysql_select_db("bus") or die(mysql_error());

     $query = " select seats.seatNo from seats where seats.isactive = 0 and seats.busID = 1";
     $result = mysql_query($query);
     while($row = mysql_fetch_array($result))
     {
         $seatNo = $row['seatNo'];
         ?>

     <option> <?php echo $seatNo ?> </option>

     <?php } ?>

    </select>

And then I'm getting selected seats here and updating the db

<?php

$con;
$link;
if(isset($_POST['submit']))
{
for($i = 0; $i<5; $i++)
{
$selected = $_POST['required'];
}
$insert = " update seats set seats.isactive = 1 where seats.seatNo = $selected and      seats.busID = 1";
$q = mysql_query($insert) or die(mysql_error());

if($q)
{
echo " record updated ";    
}

else
{
echo " couldn't update ";   
}

} 



?>
0

There are 0 best solutions below