php - Using SQL Query instead of static javascript variables

one text

Solution:

Well, the first concept you would need to get clear is that the front-end never gonna recive 'secured' data as could be the answers since it's public the front end.

So from this concept, front end gonna recive only the questions, and the possible answers, WITHOUT RECIVING which one is the correct answer from the backend.

Then the backend recives for each question, the answered answer. It does the check and returns the final result to the front end.

To do that, you have mainly 2 architectures, client-server where the the frontend is procesed by the same server that hosts the backend (old architecture)

Or API-REST where the front end is totally separated from the back end. In this architecture you gonna need a backend as you said of PHP, with its rest controllers, for that i recommend you user the LARAVEL framework.

For the frontend you can do it with Vanilla JS (Before using Jquery i recommend it), or use modern frameworks, as could be REACT, ANGULAR or VUEJS.... I personally recommend VueJS since is the easiest one to learn.

And finally to connect both services, back and front, you gonna be able to do it Through AJAX calls from the front end to the back end. To do those petitions, you have the fetch() function in JavaScript vanilla, it's way more than enougth, but if in the future, wanna go one step ahead, you can try the library AXIOS to handle the AJAX calls and use interceptors.

Hope you find this hepful, if you need something else, don't doubt in comment

Source