表单成功提交到白页

时间:2011-02-26 17:42:18

标签: php html forms

  

可能重复:
  Form Submits to white page?

所以在我的页面index.php上,有一个注册表单。表单检查错误,如果有错误,则不执行查询,但是,如果没有错误,则应该提交查询。

当用户输入所有信息并按下注册时,表单会正确提交并显示他们所做的所有错误。

但是,如果没有错误,表单将提交到白页,并且不会执行查询。

表单使用method =“POST”,只是抬头..这是PHP。

$errors=array();
if (isset($_POST['register'])) {
    if ($_POST['register']) {
        $rUsername=$_POST['usernamei'];
        $rPassword=$_POST['passwordi'];
        $rConfirm=$_POST['confirm'];
        $rEmail=$_POST['email'];
        $rProvider=$_POST['provider'];
        $rFirst=$_POST['firstname'];
        $rLast=$_POST['lastname'];
        $rRefer=$_POST['refer'];
        $allow=array('_', '-', '.');
        include 'mysqlcon.php';

        if (!$rUsername) {
            array_push($errors, 'You must enter a username!');
        } else {
            if (!ctype_alnum($rUsername)) {
                array_push($errors, 'Your username must be alphanumeric!');
            } else {
                $checkexist=(mysql_numrows(mysql_query(
                    "SELECT * FROM users WHERE username='".$rUsername."'")))
                        or die(mysql_error());
                if (!$checkexist==0) {
                    array_push($errors, 'This username is taken!');
                }
            }
            if (strlen($rUsername)>15) {
                array_push($errors, 'Your username is greater than 15 characters long!');
            }
        }

        if (!$rPassword) {
            array_push($errors, 'You must enter a password');
        } else {
            if (!ctype_alnum($rPassword)) {
                array_push($errors, 'Sorry, but passwords must be alphanumeric!');
            }
        }

        if (!$rConfirm) {
            array_push($errors, 'You must confirm your password!');
        } else {
            if (!$rConfirm==$rPassword) {
                array_push($errors, 'Your password did not match the confirmation!');
            }
        }

        if (!$rEmail) {
            array_push($errors, 'You did not enter an email!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rEmail))) {
                array_push($errors, 'Your email contained some invalid characters!');
            }
        }

        if (!$rProvider) {
            array_push($errors, 'You did not enter an email!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rProvider))) {
                array_push($errors, 'Your email provider contained some invalid characters!');
            }
        }

        if (!$rFirst) {
            array_push($errors, 'You did not enter your first name!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rFirst))) {
                array_push($errors, 'Your first name can only contain alphanumeric characters!');
            }
        }

        if (!$rLast) {
            array_push($errors, 'You did not enter your last name!');
        } else {
            if (!ctype_alnum(str_ireplace($allow, '', $rLast))) {
                array_push($errors, 'Your first name can only contain alphanumeric characters!');
            }
        }

        if ($rRefer) {
            if (!ctype_alnum(str_ireplace($allow, '', $rRefer))) {
                array_push($errors, 'Your friend\'s name can only be alphanumeric!');
            }
        }

    }
}

if (empty($errors)) {
    $isError="1";
} else {
    $isError="2";
}

20分钟后

刚刚发现,当用户转到index.php时,它会提交一个带空白字段的查询。我现在非常紧张。 :(

修改

刚打开错误报告 - 没有错误。

编辑II

这是查询代码:

if ($isError=="1") {
$userip=$_SERVER['REMOTE_ADDR'];
$today=date('Y').'/'.date('m').'/'.date('d');
$temail=$rEmail.'@'.$rProvider;
$newuser = "INSERT INTO users (username, password, firstname, lastname, email, date, ip)
VALUES  ('$rUsername', '$rPassword', '$rFirst', '$rLast', '$temail', '$today', '$userip')";
mysql_query($newuser);
}

编辑III * 好吧,所以我只是尝试了一下,似乎if语句下方的任何代码用于检查$ _POST ['register']是否存在并不执行..但是,当存在用户注册错误时,例如'你必须输入用户名!',代码执行..

0 个答案:

没有答案