0

I'm trying to make an app when users fill form, and click send button, to send informations through url parametrs like :

localhost/my.php?param1=Name&param2=SureName

I have read through internet about it, but can't get it, I found some examples but they tell how to pass through Json, I want just to send through link. (I think is easiest way )

My php code is:

<?php

require "connection.php";

if (!isset($_GET['param1'])) {
        echo '<p align="center"> No data passed!</p>"';
    }

if (strcmp($_GET['param1'],'FirstParam')== 0) 
{

$sql= "Query HERE TO ADD INTO DB";

mysqli_query($connection,$sql);

if ($connection->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $connection->error;
}

 mysqli_close($connection);
} 

Any help will be appreciated.

3
  • 1
    you should check out Retrofit library. It would make your life easier dealing with networking in your android app. Here is a tutorial vogella.com/tutorials/Retrofit/article.html Commented Feb 26, 2019 at 16:55
  • Yeah, just use retrofit mate. Commented Feb 26, 2019 at 17:07
  • I read that article but I can't find which is for my part, I found and tutorial in YouTube but all was fro json part not my case :/ I wanted to use retrofit. Commented Feb 26, 2019 at 18:47

1 Answer 1

1

I recommend to have a look on OkHttp. It is an easy library to send HTTP requests in whatever way you like. On Vogella you can also find an example of sending a GET request with additional parameters. Basically it looks like this

HttpUrl.Builder urlBuilder = HttpUrl.parse("https://api.github.help").newBuilder();
urlBuilder.addQueryParameter("v", "1.0");
urlBuilder.addQueryParameter("user", "vogella");
String url = urlBuilder.build().toString();

Request request = new Request.Builder()
                     .url(url)
                     .build();

And after that you need to send your request (asynchronously) with the help of the OkHttpClient like this

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {
        e.printStackTrace();
    }

    @Override
    public void onResponse(Call call, final Response response) throws IOException {
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        } else {
        // do something wih the result
    }
}

(Code was taken from Vogella)

Sign up to request clarification or add additional context in comments.

2 Comments

whatever library OP picks, it aint ever gonna work with localhost, either on a device or a simulator, assuming OP is not trying to run a LAMPish box in each device, but rather on some server out there.
That's right, but he can simply replace localhost with his local ip if both devices are in the same network.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.