TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Problem with PHP Forms (http://forums.techarena.in/software-development/1151769.htm)

!const 31-03-2009 09:09 PM

Problem with PHP Forms
 
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
}
>


XSI 31-03-2009 09:11 PM

Re: Problem with PHP Forms
 
1. a more explicit please
2. You Do not initialized your variables. A small error_reporting = E_ALL | E_STRICT in php.ini you do the most good.

switchblade327 31-03-2009 09:13 PM

Re: Problem with PHP Forms
 
On one page to another you do not retransmit the responses of old forms. $q1 and $q2, therefore can not exist simultaneously.

Code:

$ q1! = "" & & $ q2! = ""
and other kinds of tests are always equal to 'false'.

!const 31-03-2009 09:13 PM

Re: Problem with PHP Forms
 
Thank you I'm not good on this one. Wow it works!


All times are GMT +5.5. The time now is 06:31 PM.