Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:02:45+00:00 2026-06-15T16:02:45+00:00

I’m having trouble finding the error in my .php script. I use an android

  • 0

I’m having trouble finding the error in my .php script.

I use an android app sending post requests in order to register a user including a unique device id and email.

When sending the data my api checks if the email or device id already exist so you can’t register twice.

When registering the first time, everything works. When i try to register again with the same email it works aswell (getting the correct error). But if I use a different email (but the same device id) I get a wrong error code.

Here is the PHP-Code:

else if ($tag == 'register') {
    // Request type is Register new user
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $devid = $_POST['devid'];

    // check if user already exists
    if ($db->CheckUser($email)) {
        // user already exists
        $response["error"] = 2;
        $response["error_msg"] = "User already exists";
        echo json_encode($response);}


    else if ($db->CheckDevice($devid)) {
            // Device already exists
            $response["error"] = 3;
            $response["error_msg"] = "Device already exists";
            echo json_encode($response);}
    else {
        // store user
        $user = $db->storeUser($name, $email, $password, $devid);
        if ($user) {
            // user stored successfully
            $response["success"] = 1;
            $response["uid"] = $user["unique_id"];
            $response["user"]["name"] = $user["name"];
            $response["user"]["email"] = $user["email"];
            $response["user"]["devid"] = $user["devid"];
            $response["user"]["created_at"] = $user["created_at"];
            $response["user"]["updated_at"] = $user["updated_at"];
            echo json_encode($response);} 
        else {
           // user failed to store
           $response["error"] = 1;
           $response["error_msg"] = "Error occured in Registration";
           echo json_encode($response);}
    }
}

Check Functions:

public function CheckUser($email) {
    $result = mysql_query("SELECT email from users WHERE email = '$email'");
    $no_of_rows = mysql_num_rows($result);
    if ($no_of_rows > 0) {
        // user existed 
        return true;} 
    else {
        // user not existed
        return false;}
}


public function CheckDevice($devid) {
    $result = mysql_query("SELECT devid from users WHERE devid = '$devid'");
    $no_of_rows = mysql_num_rows($result);
    if ($no_of_rows > 0) {
        // user existed 
        return true;
    } else {
        // user not existed
        return false;
    }
}

Store Function:

public function storeUser($name, $email, $password, $devid) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt
    $result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, devid, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', '$devid', NOW())");
    // check for successful store
    if ($result) {
        // get user details 
        $uid = mysql_insert_id(); // last inserted id
        $result = mysql_query("SELECT * FROM users WHERE uid = $uid");
        // return user details
        return mysql_fetch_array($result);
    } else {
        return false;
    }
}

I’m sending

I should get this error:

$response["error"] = 3;
        $response["error_msg"] = "Device already exists";

But i am getting this one:

$response["error"] = 1;
           $response["error_msg"] = "Error occured in Registration";

Somehow when calling the CheckDevice Function it seems to return false although when I manually use SELECT devid from users WHERE devid = '$devid' in phpMyAdmin I get a true.

Then he fails to store because the device id must be unique and gives me the error (thats the only plausible explanation).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:02:46+00:00Added an answer on June 15, 2026 at 4:02 pm

    You should do some echo $devid in your CheckDevice method to see if your android device is really sending same id.

    Maybe you got error somewhere (maybe you are not sending anything when you try to register as second user from same device id).

    I think that this is yours problem (your android app).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I am writing an app with both english and french support. The app requests
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.