0

I am creating a web service for android and PHP registration process. I am following this tutorial http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

The Issue is: My JSON works on localhost but not on a server. On a server it gives me this error but it stores the data on database successfully.

Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/pmc/public_html/zeusonline.me/zeus/include/DB_Functions.php on line 45

and the line 45 is:

$user = $stmt->get_result()->fetch_assoc();

Code samples->

Register.php file

<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// json response array
$response = array("status" => TRUE);

if (isset($_GET['username']) && isset($_GET['email']) &&  
isset($_GET['country']) && isset($_GET['phone_number']) && 
isset($_GET['password']) && isset($_GET['lat']) && isset($_GET['lon'])) {

// receiving the post params
$username = $_GET['username'];
$email = $_GET['email'];
$country = $_GET['country'];
$phone_number = $_GET['phone_number'];
$password = $_GET['password'];
$lat = $_GET['lat'];
$lon = $_GET['lon'];


// check if user is already existed with the same email
if ($db->isUserExisted($email)) {
    // user already existed
    $response["status"] = FALSE;
    $response["error_msg"] = "User already existed with " . $email;
    echo json_encode($response);
}
else if ($db->isUserExisted($phone_number)) {
    // user already existed
    $response["status"] = FALSE;
    $response["error_msg"] = "User already existed with " . $phone_number;
    echo json_encode($response);
}
else {
    // create a new user
    $user = $db->storeUser($username, $email, $country , $phone_number, 
$password, $lat, $lon);
    if ($user) {
        // user stored successfully
        $response["status"] = TRUE;
        $response["user"]["uid"] = $user["unique_id"];
        $response["user"]["username"] = $user["username"];
        $response["user"]["email"] = $user["email"];
        $response["user"]["country"] = $user["country"];
        $response["user"]["phone_number"] = $user["phone_number"];
        $response["user"]["country"] = $user["country"];
        $response["user"]["height"] = $user["height"];
        $response["user"]["weight"] = $user["weight"];
        $response["user"]["is_number_verified"] = 
 $user["is_number_verified"];
        $response["user"]["is_safe"] = $user["is_safe"];
        $response["user"]["is_login"] = $user["is_login"];
        $response["user"]["lat"] = $user["lat"];
        $response["user"]["lon"] = $user["lon"];
        $response["user"]["created_at"] = $user["created_at"];
        echo json_encode($response);
    } else {
        // user failed to store
        $response["Status"] = False;
        $response["error_msg"] = "Unknown error occurred in registration!";
        echo json_encode($response);
    }
  }
} else {
$response["Status"] = TRUE;
$response["error_msg"] = "Required parameters are missing!";
echo json_encode($response);
}
?>

DB_Functions.php file

<?php

class DB_Functions {

private $conn;

// constructor
function __construct() {
    require_once 'DB_Connect.php';
    // connecting to database
    $db = new Db_Connect();
    $this->conn = $db->connect();
}

// destructor
function __destruct() {

}

/**
 * Storing new user
 * returns user details
 */
public function storeUser($username, $email, $country, $phone_number, 
$password, $lat, $lon) {
    $uuid = uniqid('', true);
    $height = 0; 
    $weight = 0;
    $is_number_verified = False;
    $is_safe = True;
    $is_login = False;
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt

    $stmt = $this->conn->prepare("INSERT INTO users (unique_id, username, 
email, country, phone_number, password, salt, height, weight, 
is_number_verified, is_safe, is_login, lat, lon, created_at) VALUES(?, ?, ?, 
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,NOW())");
    $stmt->bind_param("ssssssssssssss", $uuid, $username, $email, $country, 
$phone_number, $encrypted_password, $salt, $height, $weight, 
$is_number_verified, $is_safe, $is_login, $lat, $lon);
    $result = $stmt->execute();
    $stmt->close();

    // check for successful store
    if ($result) {
        $stmt = $this->conn->prepare("SELECT * FROM users WHERE phone_number 
= ?");
        $stmt->bind_param("s", $phone_number);
        $stmt->execute();
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

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

The URL for testing :

http://pakmanzil.com/zeusonline.me/zeus/register.php?username=bilal&[email protected]&country=england&phone_number=03333524145&password=123&lat=0.0&lon=0.0

Change the email and phone_number to make it works please :)

9
  • Possible duplicate of Call to undefined method mysqli_stmt::get_result Jul 27, 2016 at 8:20
  • 1
    Huge security issues here, you're sending clear password in GET! I would recommand you to use POST and to hash your password before sending, storing or sending clear passwords is really dangerous!
    – jeanj
    Jul 27, 2016 at 8:20
  • @MarkusLaire mysqlndrivers are updated on my server already.
    – Devilism
    Jul 27, 2016 at 8:24
  • @Vuldo Thanks, I will look into it, but can you tell me why this code is not working on server
    – Devilism
    Jul 27, 2016 at 8:37
  • Do you have the same PHP version on local and production?
    – jeanj
    Jul 27, 2016 at 8:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.