I have an array in my js file.And after the user selects his prefered seats,the data creation in the array is done.
Then I send it to a php file for displaying.The javascript code is shown below.
$('#btnsubmit').click(function(ev) {
ev.preventDefault();
var seat = [], item;
$.each($('#place li.' + settings.selectingSeatCss + ' a'), function (index, value) {
item = $(this).attr('title');
seat.push(item);
});
var bookseats = seat;
$.ajax({
type: 'POST',
url: 'confirm.php',
data: {'bookseats': bookseats}
}).then(function(data) {
alert(data);
window.location='confirm.php';
},function(err){
alert('error');
});
When sending this data,I've made an alert(data) function to see if the values are passed correctly.Below is a screenshot of the alert.
The alert clearly shows us that the array has been passed to the php page.But in my php page,no data of the array is displayed.And it shows an error saying "Invalid Arguments".
Here is my php code.
$bookseats = "";
if(isset($_POST['bookseats']))
{
$bookseats = $_POST["bookseats"];
}
print_r($bookseats);
$seatar = implode(',', $bookseats);
echo 'Booked Seats : '.$seatar.'<br>'.'<br>';
And when I try to save this array in a database,the following error is shown.
Here is the php code for data insertion to the database.
$bookings_added = $conn->query($sql);
$last_bid = $conn->insert_id;
for($i = 0; $i < count($bookseats); $i++){
$SQL_project_has_type = "INSERT INTO bookseat (seat, bid)
VALUES({$bookseats[$i]}, ".$last_bid.")";
$bs = $conn->query($SQL_project_has_type);
if($bs === FALSE) exit("mysql error: ".$conn->error);
}
Is there something wrong in my array?Please help!

