Answer the question
In order to leave comments, you need to log in
How to build logic to send data to mysql via PHP?
Good afternoon, I just started learning PHP and databases, I made a testing system, now I need to make an authorization, where the user will log in, perform the test, and at the end, I need to make sure that data about the final test result is sent to the database,
can you please explain what have to do.
I already have functions that record in themselves the number of questions, the number of correct answers, and how many percent the user passed the test, can you help with building the logic, what needs to be done first?
Answer the question
In order to leave comments, you need to log in
First do authorization. When a user logs in, record somewhere that he logged in (there are articles on the Internet with a simple solution). It will also be necessary to understand: will there be one test or more? If one test can not take a steam bath). Let's say we have several tests, then after authorization we need to redirect to the page with tests. The user selects a test (link with id to the test). Let's say we have a Questions table, and in it the question id, test id, question, answer fields. After selecting a test, a form is generated with questions from the questions table (pull out the necessary data using an sql query, and then output the input in a loop, only without an answer :) ). After clicking to finish the test, the data from the form is stored in the Answers table (answer id, question id, user id). After saving, we compare the answers between the Questions and Answers tables,
OH YES! when passing the test, check that the user is authorized))
PS: this is one of the possible implementations, not the best obviously, but it will fit for quick writing. The logic should at least be like this.
PSS: And there are different questions, for example, voluminous ones. this is when one question on the whole page. here it will be necessary to display only one input
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question