2017-12-26 8 views
-2

私はXAMPPとSQLサーバーとの簡単な接続をしようとしています。しかし、これまでにデータを入力したりデータベースに接続しようとすると、このエラーが発生します。エラーは何ですか?私は自分のプロジェクトにそれが大いに必要です。私はなぜphp 9行目がエラーであるのか分かりません。致命的なエラー:未知のエラー:未定義のメソッドを呼び出すmysqli :: error()

致命的なエラー:不明なエラー:未定義のメソッドのmysqliのに呼び出し::エラー()はC:\ xamppの\ htdocsに\ last1 \新しい\のregister.php: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"); 
     } 

    } 

私を助けてください:(ありがとう君たち; *

+0

は、データベースへの接続を確立していることでしょうか? – dede

+0

$ mysqliはどこに宣言されていますか?それは別のファイルにありますか?あなたのコードの中にある二重のアスタリスクか、あるいはこの質問の中で行を強調表示していますか? –

+0

私はそれをチェックアウトできるようにあなたに送ってきます。あなたのメールアドレスは? –

答えて

0

$mysqli->error()errorは、私はあなたが$ mysqli-を使うべきだと思うプロパティ、ない方法

+0

は、私はそれを変えたが、これは、それが「いいえデータベースが選択されていない」と表示するものである:( –

+0

G.Caps @だけでなく、あなたがあなたのDBサーバーに接続し、データベースを選択したのですか?https://secure.php.net/manual/enあなたはそれをチェックアウトすることができるように/mysqli.select-db.php – Amber

+0

メール何ですか? –

0

>の代わりに$ mysqli-のエラー>エラー() ソースであるため、$mysqli->errorする必要があります:。 210

+0

私はそれを変更したが、これは、それは「いいえデータベースが選択されていない」と表示するものである:( –

+0

ねえ、私はあなたが$ mysqliのを宣言したコードが見ることができます –

+0

変数、それは別のファイルである場合は、それは動作しません、と宣言しなかった場合は、 '(「mysqli.php」)を含む使用してそのファイルを含める;' –

0

それは
$mysqli->error
なく$ mysqli->エラー()

+0

私はそれを変えたが、これは、それが「いいえデータベースが選択されていない」を示すものです:( –

関連する問題