数据未插入数据库,警告为错误

时间:2016-12-06 15:25:02

标签: php

这是我的联系:

error_reporting(E_ALL);
ini_set('display_errors',1);

$conn = new mysqli($host, $username, $password, $database);

if($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

mysqli_close($conn);
?>

我得到了这个错误:

Warning: mysqli::mysqli(): Headers and client library minor version mismatch. Headers:50541 Library:50629 in /var/www/connection.php on line 12

然后当我想在我的数据库中插入时,这是我的代码:

<?php

require "connection.php";
error_reporting(E_ALL);
ini_set('display_errors',1);

if ($_POST['firstname'] != "" && $_POST['lastname'] !="" && $_POST['email'] != "" && $_POST['cemail'] !="" && $_POST['password'] !="" && $_POST['birthday'] !="" && $_POST['gender'] !="")
{
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $cemail = $_POST['cemail'];
    $password = $_POST['password'];
    $birthday = $_POST['birthday'];
    $gender = $_POST['gender'];


    if($email != $cemail)
    {
    header("Location: index.php/?a=1");
    }
    $query1="SELECT * FROM users WHERE firstname = '$firstname' ";  

    $result = mysqli_query($conn,$query1)
    or die(mysqli_error($conn));  

    if(mysqli_num_rows($result) != 0)
    {
        header("Location: index.php/?a=1");
    }



    else {
    $query = "INSERT INTO users (firstname,lastname,email,password,date of birth,gender) VALUES ('$firstname','$lastname','$email','$password', '$birthday' , '$gender')";


    $data = mysqli_query($conn,$query)or die(mysqli_error($conn));

    header("Location: index.php/?a=2");

    }

}


?>

我收到此错误:

Warning: mysqli_query(): Couldn't fetch mysqli in /var/www/add.php on line 24

Warning: mysqli_error(): Couldn't fetch mysqli in /var/www/add.php on line 25

第24和25行是:

$result = mysqli_query($conn,$query1)
or die(mysqli_error($conn)); 

有谁能告诉我我做错了什么,我之前做了相同的代码,一切都运行顺利,我不知道为什么现在它不起作用。甚至不是a =

0 个答案:

没有答案