php - 将 html 输入作为 php 的变量
问题描述
这是我的第一篇文章。很抱歉,如果我弄错了格式:)
我正在尝试构建一个程序,该程序使用 html 请求输入,将该输入设置为 php 变量,然后计算该变量。除了输入部分,一切都准备好了,我觉得这非常具有挑战性。我的代码如下:
<?php
$x = 1;
$answer = ($x = 1);
if($answer) {
echo "The answer is: True";
} else {
echo "The answer is: False";
}
?>
我要设置的变量是 ($x = 1) 部分。代码的目的是查看数学计算是对还是错。该代码已经过测试。
我已经在互联网上搜索了答案,遗憾的是我只看到了不同问题的答案。
解决方案
你是这个意思吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
if (isset($_POST['submit'])) {
$answer = $_POST['input'];
if($answer == 1) {
echo "The answer is: True";
} else {
echo "The answer is: False";
}
}
?>
<form action="" method="post">
Enter value: <input name="input" type="text" />
<input name="submit" type="submit" />
</form>
</body>
</html>
推荐阅读
- javascript - HTML5 音频 - 获取充满零的频率数组
- c - 如何将gets() 用于以下代码?
- angular - 角度 - 在组件中使用有条件不同布局的最佳实践
- c - 宏在 C 语言中给出了错误的值
- python - 错误:文件不以 RIFF id 开头
- r - combine_vars(vars, ind_list) 中的错误:R 中的位置必须介于 0 和 n 之间
- android - Xamarin Android GridLayout - 行跨度适用于设计器,但不适用于模拟器
- vba - 如果特定列具有数值,则复制数组
- vb.net - 如何使用连接密码使用 Vb.net 打开 Microsoft Access 数据库
- java - 如何使用 Java 为文件夹中的文件提供静态字符串?