我的注册功能有什么问题?

时间:2013-04-17 19:44:55

标签: php mysql pdo

问题&说明

您好我刚刚编写了function首先使用该名称checking if account exists in database编码,然后如果数据库中存在电子邮件,则输入该电子邮件。

如果没有,return true + insert data

但在这种情况下,nothing happens on submit,它只显示表单,但不会插入数据。 这有什么问题?

function createAccount($name, $password, $email)
{
    global $pdo;

    $check_in = $pdo->prepare("SELECT * FROM users WHERE user_name = :username LIMIT 1");
    $check_in->execute( array(':username' => $name) );

    if (!$check_in->rowCount())
    {
        $check_in = email_exists($email);
        if ($check_in === false)
        {
            $insert_in = $pdo->prepare
            ("
                INSERT INTO 
                users 
                (user_name, user_password, user_email) 
                VALUES 
                (:name, :password, :email)
            ");
            $insert_in->execute( array 
            (
                ':name' => $name,
                ':password' => $password,
                ':email' => $email
            ));

            return true;
        }
        else
        {
            return 'exists';
        }
    }
    else
    {
        return 'user_in_use';
    }   
}

function email_exists($email)
{
    global $pdo;

    $check = $pdo->prepare("SELECT * FROM users WHERE user_email = :email LIMIT 1");
    $check->execute( array(':email' => $email) );
    if ($check->rowCount())
    {
        return true;
    }
    else
    {
        return false;
    }
}

这就是我编写寄存器的方式:

# Creating shortcuts
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))
{   
    $name = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];
}

# Creating errors array

$errors = array();

if (isset($_POST['submit']))
{
    $check_in = createAccount($name, $password, $email);

    if ($check_in === true)
    {
        echo 'Created account sucessfully!';
    }
    else if ($check_in == 'already_in_use')
    {
        echo 'Could not create account because name already in use..';
    } 
    else if($check_in == 'exists')
    {
        echo 'Email already in use..';
    }
}

问题:

此代码有什么问题&我该如何解决?我没有任何错误。 它只是不会将任何数据插入数据库。

是的,PDO连接&语句是正确的,因为登录工作完美。 非常感谢!

EDIT!

    if ($check_in === true)
    {
        echo 'Created account sucessfully!';
    }
    else if ($check_in == 'already_in_use')
    {
        echo 'Could not create account because name already in use..';
    } 
    else if($check_in == 'exists')
    {
        echo 'Email already in use..';
    } else { 
    echo 'Error is there...'; 
    }

它的回声'错误就在那里......' apon提交!

1 个答案:

答案 0 :(得分:-1)

我只想打自己! 问题是:字段被设置为INT,因此我们无法存储任何东西,只有整数...