致命错误:未捕获错误:调用未定义的方法mysqli :: error()

时间:2017-12-26 03:01:37

标签: php mysql mysqli

我正在尝试与XAMPP和sql server进行简单连接。但是当我尝试输入数据或连接到数据库时,我收到此错误。错误是什么?我的项目非常需要它。我不知道为什么php第9行是错误的。

致命错误:未捕获错误:在C:\ xampp \ htdocs \ last1 \ new \ register.php中调用未定义的方法mysqli :: error():19

    <?php
    /* Registration process, inserts user info into the database 
       and sends account confirmation email message
     */

    // Set session variables to be used on profile.php page
    $_SESSION['email'] = $_POST['email'];
    $_SESSION['first_name'] = $_POST['firstname'];
    $_SESSION['last_name'] = $_POST['lastname'];

    // Escape all $_POST variables to protect against SQL injections
    $first_name = $mysqli->escape_string($_POST['firstname']);
    $last_name = $mysqli->escape_string($_POST['lastname']);
    $email = $mysqli->escape_string($_POST['email']);
    $password = $mysqli->escape_string(password_hash($_POST['password'], PASSWORD_BCRYPT));
    $hash = $mysqli->escape_string( md5( rand(0,1000) ) );

    // Check if user with that email already exists
    **$result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());**

    // We know user email exists if the rows returned are more than 0
    if ( $result->num_rows > 0 ) {

        $_SESSION['message'] = 'User with this email already exists!';
        header("location: error.php");

    }
    else { // Email doesn't already exist in a database, proceed...

        // active is 0 by DEFAULT (no need to include it here)
        $sql = "INSERT INTO users (first_name, last_name, email, password, hash) " 
                . "VALUES ('$first_name','$last_name','$email','$password', '$hash')";

        // Add user to the database
        if ( $mysqli->query($sql) ){

            $_SESSION['active'] = 0; //0 until user activates their account with verify.php
            $_SESSION['logged_in'] = true; // So we know the user has logged in
            $_SESSION['message'] =

                     "Confirmation link has been sent to $email, please verify
                     your account by clicking on the link in the message!";

            // Send registration confirmation link (verify.php)
            $to      = $email;
            $subject = 'Account Verification ( clevertechie.com )';
            $message_body = '
            Hello '.$first_name.',

            Thank you for signing up!

            Please click this link to activate your account:

            http://localhost/login-system/verify.php?email='.$email.'&hash='.$hash;  

            mail( $to, $subject, $message_body );

            header("location: profile.php"); 

        }

        else {
            $_SESSION['message'] = 'Registration failed!';
            header("location: error.php");
        }

    }

请帮帮我:(谢谢你们; *

3 个答案:

答案 0 :(得分:0)

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/> <div class="tabs"> <ul class="menu"> <li><a href="#tab-1">Tab 1</a></li> <li><a href="#tab-2">Tab 2</a></li> <li><a href="#tab-3">Tab 3</a></li> </ul> <div id="tab-1"> <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus.</p> </div> <div id="tab-2"> <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc.</p> </div> <div id="tab-3"> <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti.</p> </div> <hr> <h3><strong>Duplicate(not working)</strong></h3> <ul class="menu"> <li><a href="#tab-1">Tab 1</a></li> <li><a href="#tab-2">Tab 2</a></li> <li><a href="#tab-3">Tab 3</a></li> </ul> </div>应为$mysqli->error(),因为$mysqli->error是属性,而不是方法。

答案 1 :(得分:0)

我认为你应该使用$ mysqli-&gt;错误而不是$ mysqli-&gt; error() 资料来源:http://php.net/manual/en/mysqli.error.php

答案 2 :(得分:0)

应该是
$mysqli->error
而不是$ mysqli-&gt; error()