PHP脚本提交失败:垃圾邮件测试不起作用


PHP script failing at submit: The Spam test doesn't work

在这个jsfiddle: http://jsfiddle.net/2burL/1/是我的PHP表单的代码。

处理垃圾邮件变量的代码:

$human1 = mt_rand(0, 50); // random number to be written into this var
$human2 = mt_rand(0, 49); // same as $human1
$human_test = 0;  //declaration on the variable to be posted from the form
$spam_test = $human1 + $human2; // SUM the vars

测试代码:

$human_test = $_POST["human_test"];
    if (empty($_POST["human_test"]))
    {
        $humanerr = "This field is required.";
    }
    else if ($_POST["human_test"] != $spam_test)
    {
        $humanerr = "Wrong answer, try again.";
    }
    else
    {
    if ($_POST['submit'] && $test_error == 0 && $human_test == $spam_test)
    {

问题是,当所有必需字段设置并在提交时发布时,无论答案是对还是错,"垃圾邮件测试"每次都失败。

没有语法错误。我已经测试了$spam_test的值,它被加在一起,但是$_POST到$human_test不工作。

我得到if错误,输入值不正确。

有人看到我的代码中的错误吗?或者谁有好的方法来测试错误在哪里?

虽然看起来有些东西你不明白,你可以使用css规则要居中的div 查看小提琴:http://jsfiddle.net/LN5Zs/

<div style="height:150px; width:150px; background:red; margin:0px auto;">
<div style="height:150px; width:100px; background:yellow; margin:0px auto;">
    <div style="height:150px; width:80px; background:blue; margin:0px auto;">centered div</div>
</div>

你可以不使用左右浮动的边元素和绝对位置的中心div,这真的取决于你想要做什么

您可以使用绝对定位。将包装器div设置为position:relative,并将内部div设置为position:absolute。然后你可以随意设置它们的x和y位置,并保持中央div为top:0; left:0;

所以应该是:
div右移 - top:0; left:100%;
div left - top:0; right:100%;
div to top - bottom:100%; left:0;
div到底部 - top:100%; left:0;

这里有一个工作小提琴,提供了一个概念的例子:http://jsfiddle.net/tGYze/