0

i've been doing a seat picker system in which you can click the chair you want and it will take that chair id and insert it into the data base, i have this code

<form method="POST" id="form">
    <input type="button" value="Go to payment." name="" id="so">
<script>

  async function getChairs(){
        let url = "code/chairs.php";
        await fetch(url)
        .then(response=>response.json())
        .then(data=>{ 
            console.log();

            data.forEach(chair=>{
                var $refChair=$(".pos" + "" + chair.id);
                $refChair.attr("src","img/chair-occupied.png");
                $refChair.attr("data-bs-toggle",".popover");
                $refChair.attr("title","This chair is occupied by: ");
                $refChair.attr("data-bs-content", chair.name);
                $refChair.attr('id','2');

                new bootstrap.Popover($refChair);
                
            });
        })

    }
    getChairs()
</script>
        
<script>
cho = [];
id1 = {};


        $(".chair").on("click",function (){
            var chimba = $(this).attr("class");
            let letter1= chimba.charAt(9); 
            let letter2 = chimba.charAt(10); 
            var amazing = letter1+letter2;
            var plis = document.getElementById("so");
            plis.setAttribute("name", amazing);
            var some = plis.getAttribute("name");
            cho.push(some);
            console.log(cho);
            cho.shift(some);
            id1.id = amazing;
            cho.push(id1);
            console.log(id1);
            cho.shift(id1);
            //window.location.href="paymethod.php";
            })
</script>

I save the id from the second script in the top div, but i don't know how to take that information to php, is there a way to take those numbers to php? keep in mind that all of this is in a .php file

I tried to use event listeners, a button to send the info to the same file, i tried to insert it into an external array,

  • Your JS code can't directly talk to PHP, you have to transmit the data to the server somehow. You're already using AJAX (the `fetch` call in your code) so look for examples of sending data that way. – IMSoP Mar 25 '22 at 11:43
  • you can send another AJAX request to PHP using fetch(), to send it the selected ID. Or you can make the selection part of a form which is submitted to the server. Or you can send a GET request with the value in a URL. Or you can use websockets. Basically, all of the normal ways of sending data from a browser to a server are available to you. It's not really very clear where you're stuck, or what you've investigated or tried so far. In this scenario, since you're already using fetch for one request, it might make sense to use it again. – ADyson Mar 25 '22 at 11:45

0 Answers0