所以我是新手,我似乎无法弄清楚为什么这不起作用
如果所有文本框中都包含数字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")
}
?>
答案 0 :(得分:0)
如果有值,则您所做的将返回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");
}
}
?>
答案 1 :(得分:0)
尝试以下php代码: -
<?php
if (isset($_POST['nm1']) && isset($_POST['nm2']) && isset($_POST['nm3']) && isset($_POST['nm4']) && isset($_POST['nm5']) && $_POST['nm1'] == '1' && $_POST['nm2'] == '1' && $_POST['nm3'] == '1' && $_POST['nm4'] == '1' && $_POST['nm5'] == '1') {
header("Location: http://www.kr0kk0.tk/mainpage.php");
}
检查是否所有文本字段都设置为1,然后相应地重定向。 ?&GT;