1

我正在尝试创建一个帐户注册页面,当我添加一个系统来检查数据库并确保没有多行具有相同的用户名时,我收到 500 错误。

这是有效的代码:

<?php


if(isset ($_POST['submit']))
{
    include( 'connection.php' );

    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    if(empty($username) || empty($email) || empty($password))
    {
        echo 'Please check the required fields.';
    }
    elseif(!filter_var($email,FILTER_VALIDATE_EMAIL))
    {
        echo 'Please enter a correct email address.';
    }
    else
    {
        $password = md5($password);
        $sql = mysql_query("INSERT INTO users (email,username,password) VALUES ('$email','$username','$password')") or die(mysql_error());

        if($sql)
        {
            echo 'Successfully submitted.';
        }
    }   
}
?>

这是给我一个 500 错误的代码:

<?php
error_reporting(E_ALL)

if(isset ($_POST['submit'])) {
    include( 'connection.php' );

    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    $fetch = mysql_query("SELECT * FROM users WHERE username = '$email'") or die(mysql_error();
    $num_rows = mysql_num_rows($fetch);

    if(empty($username) || empty($email) || empty($password)) {
        echo 'Please check the required fields.';
    }
    elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
        echo 'Please enter a correct email address.';
    }

    elseif($num_rows >= 1);
    {
        echo 'This username is taken.';

    else    
    }
        $password = md5($password);
        $sql = mysql_query("INSERT INTO users (email,username,password) VALUES ('$email','$username','$password')") or die(mysql_error());

        if($sql)
        {
            echo 'Successfully submitted.';
        }
    }   
}
?>
4

3 回答 3

3

也许添加一个分号:

error_reporting(E_ALL);

编辑:

你也错过了)一个die(mysql_error();

;从_elseif($num_rows >= 1);

然后将你的else块修复为} else {

于 2012-07-07T22:09:29.943 回答
0

您在第一条语句中漏掉了一个分号

于 2012-07-07T22:10:59.453 回答
0

你有

else }

在你的代码中。那是语法错误。您正在寻找

}
else {

反而。

于 2012-07-07T22:12:01.313 回答