PHP中的单选按钮值 [英] radio button value in php

查看:152
本文介绍了PHP中的单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用php做一个简单的调查

I'm trying to make a simple survey in php

我在名为sja.php的页面上有一组单选按钮,可将其发送到sjamail.php页面

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

问题是,当我去获得

$answer = $_POST['ans'];

我看不到做类似的事情

echo "$answer";

但是如果我要给它一些逻辑

but if I were to throw some logic at it

like

    if ($answer == "ans1") {

        echo 'Correct';
    }

   else {

       echo 'Incorrect';
    }    

它将显示正确或不正确(if/else可以正确运行,并且将显示正确答案)

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

那为什么我不能以字符串形式访问单选按钮"ans"的值?

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);将返回Array ( [ans] => )

推荐答案

如果选择前四个单选按钮(ans1/2/3/4)中的任何一个,您的页面将正常工作.但是所有这些图像旁边的其余单选按钮都具有空白值,这可以解释为什么如果选择任何要测试的值,则发布的值是空的.

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.

这篇关于PHP中的单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆