PHP是或否表单

PHP是或否表单,php,html,forms,Php,Html,Forms,将用户输入与正确响应匹配的PHP表单的代码是什么?如果不相等,则返回错误,如果不相等,则显示成功消息 例如: 如果要插入的正确字符串为1234,并且用户输入3948,则应返回错误,但是,如果用户输入1234,它应该转到一个新页面。制作一个表单,调用一个php脚本作为其操作,并在该php脚本中根据“1234”或您想要的任何内容测试字段的值 if($_POST['variable'] == '1234'){ header('Location: http://www.site.com/suc

将用户输入与正确响应匹配的PHP表单的代码是什么?如果不相等,则返回错误,如果不相等,则显示成功消息

例如:
如果要插入的正确字符串为
1234
,并且用户输入
3948
,则应返回错误,但是,如果用户输入
1234
,它应该转到一个新页面。

制作一个表单,调用一个php脚本作为其操作,并在该php脚本中根据“
1234
”或您想要的任何内容测试字段的值

if($_POST['variable'] == '1234'){ 
    header('Location: http://www.site.com/success'); 
}else{
    echo 'Error Message';
}

不浪费太多时间,比如:

$answer = intval($_REQUEST['ans']);
if ( $answer == 1234 ) {
  header("Location: newpage.php");
} else {
  // add whatever you need to complete
  // the page
  echo "Error";
  // add whatever you need to complete
  // the page
}

可以是一个起点。

像这样的东西应该可以做到:

<?php
if($_POST['user_input'] == "1234"){
  header("Location: correct.php");
}elseif(isset($_POST['user_input'])){
  echo "Incorrect!";
}
?>

<form method="post" action="<?php echo $PHP_SELF;?>">
Input:<input type="text" name="user_input">
<input type="submit" value="Click!">
</form>


在那里抛出一个小标题动作,它就完成了所有的需求。