mysqli插入 - 不执行

时间:2014-01-03 19:27:17

标签: php mysqli

<?php
    require("../inc/header.inc.php");

    if(isset($_POST["username"])) {
        $username  =  strip_tags($_POST["username"]);
        $password  =  strip_tags($_POST["password"]);
        $password2 =  strip_tags($_POST["password2"]);
        $email     =  strip_tags($_POST["email"]);
        $joindate  =  date(Y-m-d);

        if(!empty($_POST["firstname"])) {
            $firstname = strip_tags($_POST["firstname"]);
        }
        else {
            $firstname = "";
        }
        if(!empty($_POST["lastname"])) {
            $lastname = strip_tags($_POST["lastname"]);
        }
        else {
            $lastname = "";
        }
        if($password!=$password2) {
            die("Your passwords don't match! Press your browsers back button to fix it.");
        }
        if(!strlen($username)> 21) {
            die("Your username is too long! Press your browsers back button to fix it.");
        }
        if(strlen($password)< 7) {
            die("Your password is too short! Press your browsers back button to fix it.");
        }
        else {
            mysqli_query($con,"INSERT INTO users(`username`,`password`,`email`,`joindate`,`firstname`,`lastname`) VALUES ('$username','$password','$email,'$date','$firstname','$lastname')");
        }
    }
?>

我今天制作了这个剧本,但最后这一切似乎与mysqli_query分开了。它没有运行它。当我输入有效数据时,它完成了它应该做的事情 - 刷新页面并清除输入。

但是 - 它不会插入数据。 my_sqli连接很好,但是某些命令不起作用,任何想法为什么?

2 个答案:

答案 0 :(得分:1)

'$email --- '$email,'$date',

中缺少引号

更改为'$email','$date',,它应该会启动。

mysqli_query($con,"INSERT INTO users(`username`,`password`,`email`,`joindate`,`firstname`,`lastname`) 
VALUES ('$username','$password','$email,'$date','$firstname','$lastname')");
                                       ^

使用:

mysqli_query($con,"INSERT INTO users(`username`,`password`,`email`,`joindate`,`firstname`,`lastname`) 
VALUES ('$username','$password','$email','$date','$firstname','$lastname')");

答案 1 :(得分:0)

啊哈!我将数据库中的日期设置为DATETIME。