已创建表,但未插入数据

时间:2011-11-24 14:17:10

标签: php mysql sql pdo

我想这可能是另一个简单的错误,我已经看了20次而没有注意到它,但是我的数据没有以某种方式插入我的数据库。

我在这个查询中做了两件事。我正在创建表,并在其中插入一些数据。不知何故正在创建表,但数据未插入其中 没有错误,没有任何迹象表明出现了问题。

查询:

$query = $dblink->prepare
(
"CREATE TABLE users
(
    id int(6) NOT NULL auto_increment,
    nick varchar(40) NOT NULL,
    name varchar(120),
    email varchar(256) NOT NULL,
    pass varchar(256) NOT NULL,
    salt binary(64) NOT NULL,
    avatar varchar(0),
    level int(1) NOT NULL,
    primary key (id)
);"
. PHP_EOL .
"INSERT INTO users
(
    nick,
    name,
    email,
    pass,
    salt,
    avatar,
    level
)
VALUES
(
    :nick,
    :name,
    :email,
    :pass,
    :salt,
    :avatar,
    5
);"
);
$query->bindParam(':nick', $_POST['step3_nick']);
$query->bindParam(':name', $_POST['step3_name']);
$query->bindParam(':email', $_POST['step3_email']);
$salt = generateSalt();
$query->bindParam(':pass', hashPassword($_POST['step3_pass'], $salt));
$query->bindParam(':salt', $salt);
unset($salt);
$query->bindParam(':avatar', $img['logo']);
$query->execute();

更大的代码块:

elseif ($step == 4)
{
    ## Stap 4 ##
    include_once('config.php');
    try
    {
        $dblink = new PDO
        (
            'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['name'],
            $config['db']['user'],
            $config['db']['pass']
        );
        $dblink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    catch (Exception $ex)
    {
        die
        (
            '<p style="color: red; font-weight: bold;">' . ($language == 'nl') ? ('Kon niet verbinden met de database!') : ("Couldn't connect to the database") . '</p>' . PHP_EOL .
            '<p style="color: red;">' . $ex . '</p>'
        );
    }
    if ($_POST['step3_pass'] !== $_POST['step3_pass_confirm'])
    {
        die
        (
            '<p style="color: red; font-weight: bold;">' . ($language == 'nl') ? ('De opgegeven wachtwoorden komen niet overeen!') : ("The given passwords don't match!") . '</p>'
        );
    }
    $query = $dblink->prepare
    (
        "CREATE TABLE users
        (
            id int(6) NOT NULL auto_increment,
            nick varchar(40) NOT NULL,
            name varchar(120),
            email varchar(256) NOT NULL,
            pass varchar(256) NOT NULL,
            salt binary(64) NOT NULL,
            avatar varchar(0),
            level int(1) NOT NULL,
            primary key (id)
        );"
        . PHP_EOL .
        "INSERT INTO users
        (
            nick,
            name,
            email,
            pass,
            salt,
            avatar,
            level
        )
        VALUES
        (
            :nick,
            :name,
            :email,
            :pass,
            :salt,
            :avatar,
            5
        );"
    );
    $query->bindParam(':nick', $_POST['step3_nick']);
    $query->bindParam(':name', $_POST['step3_name']);
    $query->bindParam(':email', $_POST['step3_email']);
    $salt = generateSalt();
    $query->bindParam(':pass', hashPassword($_POST['step3_pass'], $salt));
    $query->bindParam(':salt', $salt);
    unset($salt);
    $query->bindParam(':avatar', $img['logo']);
    $query->execute();

    echo ($language == 'nl') ? ('<strong>Installatie voltooid!</strong>') : ('<strong>Setup completed!</strong>');
    ?>
        <form action="index.php" method="POST">
            <input type="checkbox" name="step4_removesetupfile" /><?php echo ($language == 'nl') ? ('Verwijder <em>setup.php</em>.') : ('Remove <em>setup.php</em>.'); ?>
            <input type="submit" value="»" />
        </form>
    <?php
}

此外,表value中的settings列未获得任何值,而$language确实有值。

2 个答案:

答案 0 :(得分:1)

我建议您执行FLUSH TABLE请求。

答案 1 :(得分:0)

这只是一个错字,像往常一样&gt;。&lt;
这是一个你们两个都找不到的,因为我从它获得POST数据的形式发了一个拼写错误。