I am new to PHP, I am making a Quiz page. The answers in FORM are sent to test-submit.php as follow:
question1-answer1; question2-answer2; question3-answer2...
http://localhost/tracy/test-submit.php?q1=a1&q2=a1&q3=a2&q4=a1
So I am confused how to get all the data separately to import to SQL database?
What if I have 1000 questions in URL? Iam looking for any help. Really appreciated!!!
I tried with $_GET['']
but I don't know what to get. is it:
$_GET['q1'];
$_GET['q2'];
$_GET['q3'];
$_GET['q4'];
$_GET['q5'];
You can loop through all the query params
and check if the value corresponding to the key exists
foreach($_GET as $key => $val) {
if(!empty($val)) {
$save[$key] = $val;
}
}
Then you can process the final $save
array as you want.
More importantly, if you have 1000 questions, means large form value and doing database operations, you should use POST
method instead of GET
. In that case the loop will be similar:
foreach($_POST as $key => $val) {
if(!empty($val)) {
$save[$key] = $val;
}
}