php - org.json.JSONException: Value DB of type java.lang.String cannot be converted to JSONObject

642

I'm making an Android login feature. Originally, it was made using localhost, but it is re-created with free hosting because it wants to have an external connection.

I uploaded php over FTP and changed url, which used to be localhost, to a free hosting url.

    final static private String URL = "http://10.0.2.2:80/login.php";

to

    final static private String URL = "http://stock123.dothome.co.kr/login.php";

When using a local host, it was run as an AVD, and when using a free hosting url, it was run as an Android device.

When using a local host, the login is executed without any problem, but after changing url, an error occurs below.

org.json.JSONException: Value DB of type java.lang.String cannot be converted to JSONObject


I don't know where the problem is.
This is login.php

<?php


  $con = mysqli_connect('mirpasec.ddns.net:50106', 'extern_user', 'extern_pass', 'extern_user');

 if (!$con)
  {
     echo "MySQL 접속 에러 : ";
     echo mysqli_connect_error();
     exit();
  } else {
    echo "DB connect success";
  }

     $userID = $_POST["userID"];
     $userPassword = $_POST["userPassword"];

     $statement = mysqli_prepare($con, "SELECT * FROM USER WHERE userID = ? AND userPassword = ?");
     mysqli_stmt_bind_param($statement, "ss", $userID, $userPassword);
     mysqli_stmt_execute($statement);
     mysqli_stmt_store_result($statement);
     mysqli_stmt_bind_result($statement, $userID, $userPassword, $userEmail, $userName, $userPhone);

     $response = array();
     $response["success"] = false;

     while(mysqli_stmt_fetch($statement)){
      $response["success"] = true;
      $response["userID"] = $userID;
      $response["userPassword"] = $userPassword;
      $response["userEmail"] = $userEmail;
      $response["userName"] = $userName;
      $response["userPhone"] = $userPhone;
     }

     echo json_encode($response);
?>

I don't think there is a problem with json code because it worked normally when using the local host. There seems to be a problem connecting to the DB. Is there anything else I need to add when using FTP?

446

Answer

Solution:

Value DB of type java.lang.String cannot be converted to JSONObject

I think the issue is you are not getting yourJSONObject because somehow you didn't reach your backend api .

please check if you have necessary permission in yourAndroidManifest.xml file. You need to add the following permission to grant your application to use the internet.

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

People are also looking for solutions to the problem: php - Stubbing child methods fails when testing parent method

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.