views:

437

answers:

4

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] => )

+2  A: 

Perhaps the value is something other than text.

Try

var_dump($answer);

or

print_r($answer, TRUE);
DKinzer
var_dump($answer); displays "NULL"
Crash893
print_r($answer, TRUE); doesn't display anything
Crash893
print_r($_POST); prints "Array ( [ans] => ) "
Crash893
+1  A: 

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

Brant
confirmed POST and yes each value is different
Crash893
I just checked your form. Look like the output is correct. I clicked on 4 and submit and the output confirmed my selection. Try a different browser.
Brant
+1  A: 

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.

Marc B
YOU ARE THE WINNAR!!!! the script in the first page was using the wrong variable for the value field (when creating the radio buttons).
Crash893
A: 

try this:

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

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

Lea