php - 无法显示php文件的结果,帮帮我
问题描述
我不知道为什么它不能显示结果。我已经在上面放了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";
}
}
?>
解决方案
您的按钮的类型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>
推荐阅读
- javascript - 即使设置了 crossOrigin,fabric.Image.fromURL 上的交叉原点也会破坏 CORS
- c# - Serilog 将日志记录到控制台但不记录到文件
- php - 使用 datepicker 插入 PHP 日期
- linux - 在 Linux Mint 19.1 cinnamon 上配置 pytorch-kaldi 时出错
- reactjs - 从打字稿中的对象破坏属性
- makefile - 使用 autoconf 链接外部对象文件 (.o)
- php - 如何立即从数据库中检索数据然后插入?
- javascript - Vue.js 动态组件未创建但显示在控制台中
- firebase - 当路径中的数据不存在时,如何使用 Go Firebase-Admin SDK 检测空结果
- r - 使用 dplyr 将多列连接为一列