2017-05-17 5 views
0

私はこのPHPファイルをサーバーに保存しています。 DBの新しいユーザーを作成します。登録は成功しましたが、応答メッセージは常にNULLです。 :ここではbind_resultのphp null値

は私が

<?php 

require_once 'DB_Functions.php'; 
$db = new DB_Functions(); 

// json response array 
$response = array("error" => FALSE); 

if (($_POST['name']) && ($_POST['surname']) && ($_POST['email']) && ($_POST['password']) && ($_POST['telephone'] && ($_POST['country']))) 
{ 
    // receiving the post params 
    $name = $_POST['name']; 
    $surname = $_POST['surname']; 
    $email = $_POST['email']; 
    $password = $_POST['password']; 
    $telephone = $_POST['telephone']; 
    $country = $_POST['country']; 

    // check if user is already existed with the same email 
    if ($db->isOwnerExisted($email)) { 
     // user already existed 
     $response["error"] = TRUE; 
     $response["error_msg"] = "User already exists with " . $email; 
     echo json_encode($response); 
    } else { 
     // create a new user 
     $user = $db->storeOwner($name, $surname, $email, $password, $telephone, $country);   
     if ($user) { 
      // user stored successfully   
      $response["error"] = FALSE; 
      $response["oid"] = $user["oid"]; 
      $response["user"]["name"] = $user["name"]; 
      $response["user"]["surname"] = $user["surname"]; 
      $response["user"]["country"] = $user["country"]; 
      $response["user"]["email"] = $user["email"]; 
      $response["user"]["password"] = $user["password"]; 
      $response["user"]["telephone"] = $user["telephone"]; 

      echo json_encode($response); 
     } else { 
      // user failed to store 
      $response["error"] = TRUE; 
      $response["error_msg"] = "Unknown error occurred in registration!"; 
      echo json_encode($response); 
     } 
    } 
} else { 
    $response["error"] = TRUE; 
    $response["error_msg"] = "Required parameters are missing!"; 
    echo json_encode($response); 
} 
?> 

そしてstoreOwner機能

public function storeOwner($name, $surname, $email, $password, $telephone, $country) { 
    $hash = $this->hashSSHA($password); 
    $encrypted_password = $hash["encrypted"]; // encrypted password 
    $salt = $hash["salt"]; // salt 
    $stmt = $this->conn->prepare("INSERT INTO owner (oid, name, surname, country, email, password, salt, telephone) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); 
    $stmt->bind_param("isssssss", $oid, $name, $surname, $country, $email, $encrypted_password, $salt, $telephone); 
    $result = $stmt->execute(); 
    $stmt->close(); 

    // check for successful store 
    if ($result) { 
     $stmt = $this->conn->prepare("SELECT * FROM owner WHERE email = ?"); 
     $stmt->bind_param("s", $email); 
     $stmt->execute(); 
     $user = $stmt->bind_result($user['oid'], $user['name'], $user['surname'], $user['country'], $user['email'], $user['password'], $user['salt'], $user['telephone']); 
     while ($stmt->fetch()) { 
       //printf("%s %s\n", $email, $password); 
     } 
     $stmt->close(); 

     return $user; 
    } else { 
     return false; 
    } 
} 

値が出力さ

{ "エラー" のようなものです投稿私のregister.phpファイルですnull "、" null "、" null "、" email ":null、" password ":null、" telephone ":null}}

なぜすべてのフィールドがNULLですか?

$user = $stmt->bind_result($user['oid'], ...); 

(エラーの成功と偽の真の)ブール値を返します$stmt->bind_result()方法:ユーザーをフェッチしているとき

+0

? '$ user = $ stmt-> bind_result(...)'は '$ user'を' true'または 'false'に設定します(そのメソッドはブール値を返します)。 –

+0

$ oidはDBの自動インクリメント値ですが、定義していません – Kzaf

+0

それから、クエリからすべて削除します。データベースはすべてそれを単独で処理します。今のところ、 'oid'を未定義の変数に設定しようとしています。 –

答えて

6

、あなたは現在、そのメソッドからの応答を結合した結果を上書きしています。つまり、コードは最初に値を設定し、完了すると、メソッドの結果(ブール値)で上書きします。

それは次のようになります。 `$が定義されますoid`ん

$user = []; // You should create the array before using it. 
$stmt->bind_result($user['oid'], ...);