无法显示php文件的结果,请帮助我

时间:2019-12-21 09:42:11

标签: php html forms

我不知道为什么它不能显示结果。我已经在上面放了isset()函数,但是回显字符串没有出来。

<form method="POST">
    <input type="radio" name="colors" value="red" checked="true"> 
    <label id="r">Red</label>
    <input type="radio" name="colors" value="green">
    <label id="g">Green</label>

    <input type="button" name="add" value="Add">
    <input type="button" name="clear" value="Clear">
</form>


<?php
    if (isset($_POST['add'])) {
        if (isset($_POST['colors'])) {
            $colorVal = $_POST['colors'];
            echo "$colorVal";
        }
    }
?>

2 个答案:

答案 0 :(得分:2)

您的Add按钮的类型必须为submit,并且Clear按钮也必须为reset。 顺便说一下,$POST['colors']必须是$_POST['colors']

<form method="POST">
    <input type="radio" name="colors" value="red" checked="true"> 
    <label id="r">Red</label>
    <input type="radio" name="colors" value="green">
    <label id="g">Green</label>

    <input type="submit" name="add" value="Add">
    <input type="reset" name="clear" value="Clear">
</form>


<?php
if (isset($_POST['add'])) {
    if (isset($_POST['colors'])) {
        $colorVal = $_POST['colors'];
        echo "$colorVal";
    }
}
?>

更新 :(重置按钮可以正常工作)

<form method="POST">
    <input type="radio" name="colors" value="red" checked="true"> 
    <label id="r">Red</label>
    <input type="radio" name="colors" value="green">
    <label id="g">Green</label>

    <input type="submit" name="add" value="Add">
    <input type="reset" name="clear" value="Clear">
</form>

答案 1 :(得分:0)

$ echo "export * from './animation/AnimationAction';" >> node_modules/three/src/Three.d.ts 

通过将其类型设置为SUBMIT来定义一个提交按钮(用于提交表单)

<form method="POST">
   <input type="radio" name="colors" value="red" checked="true"> 
   <label id="r">Red</label>
   <input type="radio" name="colors" value="green">
   <label id="g">Green</label>
   <input type="submit" name="add" value="Add">
   <input type="reset" name="clear" value="Clear">
</form>
<?php
   if(isset($_POST['add']))
   {
       if(isset($_POST['colors']))
       {
            $colorVal = $_POST['colors'];
           echo "$colorVal";
       }
   }
?>
  

<input type="submit"> 定义了一个可点击的按钮(通常与   JavaScript来激活脚本)。

此外,您在$ _POST上遇到语法错误

相关问题