数据库连接成功但未插入数据

时间:2016-08-23 09:37:47

标签: php mysqli phpmyadmin

帮助PLZ,我无法在我的数据库中插入数据。我检查了很多表格,但没有运气。

 <?php

    $DBhost = "localhost";
    $DBuser = "root";
    $DBpass = "mysql";
    $DBname = "blog";

    $DBcon = new MySQLi($DBhost,$DBuser,$DBpass,$DBname);

    if ($DBcon->connect_errno) {
        die("ERROR : -> ".$DBcon->connect_error);
    } else {
     echo "Successfully Connected";
    }

    if(isset($_POST['signup'])) {

        $fn = strip_tags($_POST['first_name']);
        $ln = strip_tags($_POST['last_name']);
        $email = strip_tags($_POST['email']);
        $ce = strip_tags($_POST['confirm_email']);    
        $pass = strip_tags($_POST['password']);
        $bd = strip_tags($_POST['birth_day']);
        $ay = strip_tags($_POST['about_yourself']);
        $image = strip_tags($_FILES['image']['name']);    


        $fn = $DBcon->real_escape_string($fn);
        $ln = $DBcon->real_escape_string($ln);
        $email = $DBcon->real_escape_string($email);
        $ce = $DBcon->real_escape_string($ce);
        $pass = $DBcon->real_escape_string($pass);
        $bd = $DBcon->real_escape_string($bd);
        $ay = $DBcon->real_escape_string($ay);
        $image = $DBcon->real_escape_string($image);

        $hashed_password = password_hash($pass, PASSWORD_DEFAULT); // this function works only in PHP 5.5 or latest version

        $check_email = $DBcon->query("SELECT email FROM form WHERE email='$email'");
        $count=$check_email->num_rows;

        if ($count==0) {

            $query = "INSERT INTO form(first_name,last_name,
                                        email,confirm_email,
                                        password,birth_day,
                                        about_yourself,image)               
                        VALUES('$fn','$ln',
                               '$email','$ce',
                               '$hashed_password','$bd',
                                '$ay','$image')";

        if ($DBcon->query($query)) {
            $msg = "<div>
                    successfully registered !
                    </div>";
        }else {
            $msg = "<div>
                    error while registering !
                    </div>";
        }

    } else {

        $msg = "<div>
             sorry email already taken !
            </div>";
    }

     $DBcon->close();
}
?>

这是代码。我对php很新,想要制作动态注册表单。每当我运行查询时,都不会在数据库中插入任何内容。什么可能是错的?

0 个答案:

没有答案