-2

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="https://image.flaticon.com/icons/png/512/24/24868.png"; seats.push(id); alert(seats); } </script>

Suchith
  • 5
  • 2

1 Answers1

0

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

ajitpawarink
  • 436
  • 6
  • 14
  • I'm getting a error when I click on the button to which I've added a onclick function.The error says "$ is undefined", referring to $.ajax – Suchith Jan 11 '21 at 12:34
  • You are missing Jquery [So classic problem](https://stackoverflow.com/questions/14971394/javascript-runtime-error-is-undefined) – ajitpawarink Jan 12 '21 at 04:14