skip to Main Content

I created a database on cpanel and i choosed a name and pass for it.
So i declared “database”,”password”,”user name”,”localhost” in services.php.

Services.php:

  <?php
  if (isset($_REQUEST['action'])){
  $foo = $_REQUEST['action'];
  }else{
  echo "Invalid Data";
  exit;
  }

  /*************************************************/
 function connectToDatabase()
   {
    $servername ="localhost";
    $username = "us_utab";
    $password = "sk3%CkvH";
    $dbname = "us_utab";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
     $conn->set_charset("utf8");
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);

    } 
    return $conn;
    }

    /*************************************************/

   if ($foo == 'search')
   { search(); }

   if ($foo == 'read')
   { read();}

   if ($foo == 'insert')
   { insert();}

   .
   .
   .

I changed my android code.

HttpPost method = new HttpPost("http://192.168.1.2/test-website/services.php?action=read"); 

To :

HttpPost method = new HttpPost("https://utab.com:2083/services.php?
action=read");

Is this correct?

It is not need to use database name , password , user name in android place?

It does not connect to server . so I deleted port 2083 and I am encountering error in below :

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

2

Answers


  1. Well your code seems to be correct and not the problem in this case.

    It is not need to use database name , password , user name in android place?

    Nope you don’t have to if the PHP file already contains these values.

    The actual error we are seeing is a SSLPeerUnverifiedException which means that the Certificate of https://utab.com has some issues. So you need to check on that. Also check the date of your device, is it correct?

    Login or Signup to reply.
  2. javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
    

    That means you are trying to do a secure https connection to a http server that doesn’t expect for secure connections.

    $servername ="localhost";
    $username = "us_utab";
    $password = "sk3%CkvH";
    $dbname = "us_utab";
    

    Is that the only contents of services.php ? If yes then it lacks all the code to connect to the database, get arguments from the http request, make probably some database query and return some response. It seems that if the only one argument is action=read it is not clear what it must respond.

    UPDATE

    After reading your comment, if the server is accessible from the same computer but not from another computer then you have an IP routing problem, not a programming problem. May the computer on the server resides has a firewall that blocks incoming connections, or its network interface is misconfigured.

    Take also in account that inside a LAN the public IP with which the router connects to the WAN is not accessible from the LAN computers. For testing inside the LAN you have to use the private LAN IPs, for example 192.168.1.2, not “utab.com”

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search