Converting Javascript array to PHP array or passing it to a PHP file

I am working on a movie ticket booking database using Mysql and PHP.I've done the frontend part using HTML,CSS. The below code is to change the image of the selected seat.The Available seats are shown in red,the booked ones are white. When the user clicks on a red image it'll turn to black,to show that the seat has been selected.But i need the list of seats which are selected by the user,in other words, i want the name of the seats,the user have booked.All seats have a seat name associated with the image.I'm stuck at this point,the seat names are stored in "seats" array of javascript. But i need this data into php to update the same into my database.I've no knowledge on JSON,AJAX.etc. please help me resolve this. Thank you.

<script > var seats=[]; function sample(id){ document.getElementById(id).src=""; seats.push(id); alert(seats); } </script>

1 answer

  • answered 2021-01-11 05:47 A_J

    As I understand, once image for seat is clicked you are storing that in seats array & marking that image as black/selected.

    Now you must have some Continue/Proceed/Book button to finalize selected seats.

    Now add a onclick function to that button & in that function you need to create an ajax request to PHP

    to pass seats array with Ajax refer here