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

  • SEARCH
  • Home
  • 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 6055831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:30+00:00 2026-05-23T08:18:30+00:00

I am getting a problem in PHP. I am trying to pass the username/password

  • 0

I am getting a problem in PHP. I am trying to pass the username/password from Android and checking the value in MySQL through PHP. While using json_decode and json_encode, json_decode works but json_encode does not work. But when I remove the json_decode, json_encode works, but I want both of them to work in my program.

Here is my code:

$a = $_POST['userpwd_value']; //Accesing the value from Android.

$b = json_decode($a); //Decoding android value using JSON.

$username = $b->{'username'}; //Assigning username from android to a variable.
$password = $b->{'password'}; //Assigning password from android to a variable.

echo $username.$password;

$check = mysql_query("select username,password from user where id=1");
$row = mysql_fetch_assoc($check);

//if($row['username']==$username && $row['password']==$password)
    $output[]=$row;
//else
    //$output[]=array("value"=>"false");
print(json_encode($output));

Where is the problem?

  • 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-05-23T08:18:31+00:00Added an answer on May 23, 2026 at 8:18 am

    json_encode fails if the variable content is not correctly UTF-8 sequenced. If your database uses another charset, the variables contain special characters, then you should get an error there. (raise the error_reporting level or check json_last_error to find out)

    Another problem with your specific code is that you first output something else:

     echo $username.$password;
    

    This will invalidate the JSON output as a whole. If you have leading garbage, your browser will not decode the returned variables correctly. Also don’t forget to send the appropriate header with your result usingheader("Content-Type: application/json");


      $b=json_decode($_POST['userpwd_value']); 
      $username=$b->{'username'}; 
      $password=$b->{'password'};
    
      $check = mysql_query("select username,password from user where id=1");
      $row = mysql_fetch_assoc($check);
      $row = array_map("utf8_encode", $row);
    
      if ($row['username']==$username && $row['password']==$password) {
          $output[] = $row;
      } else {
          $output[] = array("value"=>"false");
      }
      header("Content-Type: application/json");
      print(json_encode($output));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert data in table in mysql database through php code
I'm trying to parse some XML using simpleXML in PHP. The problem I'm having
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm slowly getting back into PHP, and now I run into a problem, I
I am getting problem to read pdf files using iText in java. I can
I am having problem getting my tooltip to work when using the jQuery load()
I am having a problem getting a list of fields from a query defined
I'm trying to solve Project Euler #9, which is http://projecteuler.net/index.php?section=problems&id=9 . I've looked through
I'm having a problem with some PHP code I'm trying to use. I keep
Anyone got a problem with php 5.2.12 getting a lot of Maximum execution time

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.