I have a concern for PHP. I'm trying to code a test system, or survey, but it does not work. It returns me directly to the result, knowing that $result is $ q2 ... I do not understand this.. Could you enlighten me on this? Here is the code:
PHP Code:
<? php
if (isset ($ _POST [ 'q1'])){
$ q1 = $ _POST [ 'q1'];
}
if (isset ($ _POST [ 'q2'])){
$ q2 = $ _POST [ 'q2'];
}
if (isset ($ _POST [ 'q3'])){
$ q3 = $ _POST [ 'q3'];
}
if (isset ($ _POST [ 'q4'])){
$ q4 = $ _POST [ 'q4'];
}
if (isset ($ _POST [ 'q5'])){
$ q5 = $ _POST [ 'q5'];
}
if ($ q1 == "" & & $ q2 == "" & & $ q3 == "" & & $ q4 == "" & & $ q5 == "") {
echo '
<form action="tests.php" method="post">
<input type="radio" name="q1" value="1"> Yes <br/>
<input type="radio" name="q1" value="3"> No <br/>
<input type="radio" name="q1" value="5"> No opinion <br/>
<input type="submit" value="Valid">
</form> ';
}
else if ($ q1! = "") {
echo '
<form action="tests.php" method="post">
<input type="radio" name="q2" value="1"> Yes <br/>
<input type="radio" name="q2" value="3"> No <br/>
<input type="radio" name="q2" value="5"> No opinion <br/>
<input type="submit" value="Valid">
</form> ';
}
else if ($ q1! = "" & & $ q2! = "") {
echo '
<form action="tests.php" method="post">
<input type="radio" name="q3" value="1"> Yes <br/>
<input type="radio" name="q3" value="3"> No <br/>
<input type="radio" name="q3" value="5"> No opinion <br/>
<input type="submit" value="Valid">
</form> ';
}
else if ($ q1! = "" & & $ q2! = "" & & $ q3! = "") {
echo '
<form action="tests.php" method="post">
<input type="radio" name="q4" value="1"> Yes <br/>
<input type="radio" name="q4" value="3"> No <br/>
<input type="radio" name="q4" value="5"> No opinion <br/>
<input type="submit" value="Valid">
</form> ';
}
else if ($ q1! = "" & & $ q2! = "" & & $ q3! = "" & & $ q4! = "") {
echo '
<form action="tests.php" method="post">
<input type="radio" name="q5" value="1"> Yes <br/>
<input type="radio" name="q5" value="3"> No <br/>
<input type="radio" name="q5" value="5"> No opinion <br/>
<input type="submit" value="Valid">
</form> ';
}
else {
$result = $q1 + $q2 + $q3 + $q4 + $q5;
echo $result;
}
>
Bookmarks