package com.example.maybe;
import android.content.Context;
import android.os.AsyncTask;
import android.text.Html;
import android.widget.TextView;
import androidx.loader.content.AsyncTaskLoader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class GetData extends AsyncTask<String, Void, String > {
private Context context;
private TextView text;
private int id = 1;
public GetData(Context context, TextView text, int day){
this.context= context;
this.text = text;
this.id = day;
}
protected void onPreExecute(){
}
@Override
protected String doInBackground(String... arg0){
try {
String link ="https://bdforandroid.000webhostapp.com/getBD.php";
String data = URLEncoder.encode("id", "UTF-8") + "-" +id;
URL url = new URL(link);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null){
sb.append(line);
break;
}
return sb.toString();
} catch (Exception e){
return new String("Exception: " + e.getMessage());
}
}
@Override
protected void onPostExecute(String result){
this.text.setText(Html.fromHtml(result));
}
}
$con=mysqli_connect("localhost", "id16937257_cheta", "d0VALqS!8%q~kYXh", "id16937257_bdforandroid");
$id = $_POST['id'];
$result = mysqli_query($con,"SELECT `date` FROM `holidays` WHERE `id` = $id");
$row = mysqli_fetch_array($result);
$data = $row[0];
echo $data;
mysqli_close($con);
мне нужно отправить поле id из AndroidStudio
Создал класс для подключения к бд,
String link ="https://bdforandroid.000webhostapp.com/getBD.php";
String data = URLEncoder.encode("id", "UTF-8") + "-" +id;
если не использовать id, то информация возвращается
$id = $_POST['id'];
$result = mysqli_query($con,"SELECT `date` FROM `holidays` WHERE `id` = $id");