Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的寄存器功能有什么问题?_Php_Mysql_Pdo - Fatal编程技术网

Php 我的寄存器功能有什么问题?

Php 我的寄存器功能有什么问题?,php,mysql,pdo,Php,Mysql,Pdo,问题与解释 您好,我刚刚编写了一个函数,该函数首先检查数据库中是否存在使用该名称的帐户,然后检查数据库中是否存在使用该输入电子邮件的电子邮件 如果不是,则返回true+插入数据 但是在这种情况下,提交时不会发生任何事情,它只显示表单,而不会插入数据。。 怎么了 function createAccount($name, $password, $email) { global $pdo; $check_in = $pdo->prepare("SELECT * FROM us

问题与解释

您好,我刚刚编写了一个函数,该函数首先检查数据库中是否存在使用该名称的帐户,然后检查数据库中是否存在使用该输入电子邮件的电子邮件

如果不是,则返回true+插入数据

但是在这种情况下,提交时不会发生任何事情,它只显示表单,而不会插入数据。。 怎么了

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连接和语句是正确的,因为登录工作得非常好。 非常感谢

编辑


它在回响“有错误…”apon submit

我只想打自己一巴掌!。。。。。
问题是:字段设置为INT,因此我们只能存储INT…

能否显示表单?可能出了什么问题?只是添加了表单。在这种情况下,我犯的一个典型错误是发现有多个表具有相同的名称,但模式不同。由于未指定架构,可能它将进入一个您不期望的表。@YourCommonSense我已经有了错误报告,每当我在语法中出现错误时,它都会说。我已经有了一些并修复了它们,现在没有错误,仍然不起作用。
    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...'; 
    }