开发者

radio button value in php

I'm trying to make a simple survey in php

I have a set of radio buttons on a page called sja.php that sends its to sjamail.php page

the problem is that when I go to get

$answer = $_POST['ans'];

I can't seen to do anything like

echo "$answer";

but if I were to throw some logic at it

like

    if ($answer == "ans1") {

        echo 'Correct'开发者_开发技巧;
    }

   else {

       echo 'Incorrect';
    }    

It will display correct or incorrect (edit: The if/else works correctly and will display the correct answer )

so why is it I can't access the value of the radio button "ans" as a string?

http://www.markonsolutions.com/sja.php

print_r($_POST); will return Array ( [ans] => )


Perhaps the value is something other than text.

Try

var_dump($answer);

or

print_r($answer, TRUE);


Your page works correctly if you select any of the first 4 radio buttons (ans1/2/3/4). But the rest of the radio buttons next to all those images have blank values, which would explain why your posted value is empty if you selected any of those to test with.


You need to make sure that the field in HTML has...

<input type="radio" name="ans" value="ans1" />
<input type="radio" name="ans" value="ans2" />

Also make sure your form method is POST


I had a similar problem with the following:

     <input name="03 - Gender" type="radio" value="Masculino"/>Male<br/>
     <input name="03 - Gender" type="radio" value="Femenino" required="required"/>Female <br/>
     <input type="hidden" name="03 - Gender" value=""/>

but when I removed the third input line (the hidden one) the problem desapeared.


Try this:

$answer = (string)$_POST["ans"];
echo $answer;

You must convert $_POST["ans"] to string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜