php - 如果 all = 1,则检查 php 中的 html 输入,重定向
问题描述
所以我对此很陌生,我似乎无法弄清楚为什么这不起作用
如果所有文本框都包含数字 1,我希望 php 文件重定向我。
到目前为止,这是我的代码:
html file:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styleIndex.css">
</head>
<body>
<div class="middle">
<h1>ENTER CODE</h1>
</div>
<div class="Code">
<form action=action.php method="post">
<input type="text" placeholder="0" maxlength="1" name="nm1" required>
<input type="text" placeholder="0" maxlength="1" name="nm2" required>
<input type="text" placeholder="0" maxlength="1" name="nm3" required>
<input type="text" placeholder="0" maxlength="1" name="nm4" required>
<input type="text" placeholder="0" maxlength="1" name="nm5" required>
<input type="submit" name="submit" hidden>
</form>
</div>
</body>
</html>
action.php 文件:
<?php
if (isset($_POST['nm1']) && ($_POST['nm2'] && ($_POST['nm3'] && ($_POST['nm4'] && ($_POST['nm5'] ='1') {
header("Location: http://www.kr0kk0.tk/mainpage.php")
}
?>
解决方案
如果其中有值,您所做的将返回 true,但是它不会检查它包含的值。你应该这样做:
<?php
if(isset($_POST['submit']) {
if(($_POST['nm1'] == 1) && ($_POST['nm2'] == 1) && ($_POST['nm3'] == 1) && ($_POST['nm4'] == 1) && ($_POST['nm5'] == 1)) {
header("Location: http://www.kr0kk0.tk/mainpage.php");
}
}
?>
推荐阅读
- laravel - 当我将令牌发送到 heroku 上部署的 api 时,我无法获取令牌
- linux - 安装 OMNeT++ 的问题
- flutter - 如何在颤振中实现 GPS 状态变化监听器
- ruby-on-rails - rails ActiveModel::Validations 中的数据类型验证
- electron - Electron 是否支持 4K USB 视频分辨率?
- azure-devops - AzureDevOps 导出 ProcessTemplate
- c++ - 从 char 数组中删除双空格
- c++ - 在模板中使用 noexcept 运算符
- webpack - 如何在使用模板时遍历 html-webpack-plugin 中的数组
- python - Django:为不同的代码部分添加“配置”列表以访问