Last active
March 9, 2018 12:34
-
-
Save sharifulislam52/9ae4558bdc2ac28506c7345606125e9e to your computer and use it in GitHub Desktop.
A complete example of android with mySQL database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.app.AlertDialog; | |
import android.content.Context; | |
import android.os.AsyncTask; | |
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.OutputStream; | |
import java.io.OutputStreamWriter; | |
import java.net.HttpURLConnection; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.net.URLEncoder; | |
import javax.net.ssl.HttpsURLConnection; | |
/** | |
* Created by Shariful Islam on 02/03/2018. | |
*/ | |
public class BackgroundWorker extends AsyncTask<String,Void,String> { | |
Context context; | |
AlertDialog alertDialog; | |
BackgroundWorker(Context context){ | |
this.context = context; | |
} | |
@Override | |
protected String doInBackground(String... voids) { | |
String type = voids[0]; | |
String login_url = "https://your_domain_name/login.php"; | |
String register_url = "https://your_domain_name/register.php"; | |
String update_url = "http://your_domain_name/update_data.php"; | |
String deleted_url = "http://your_domain_name/delete_data.php"; | |
if (type.equals("login")){ | |
try { | |
String username = voids[1]; | |
String password = voids[2]; | |
URL url = new URL(login_url); | |
// login url link is "http" link | |
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection(); | |
httpsURLConnection.setRequestMethod("POST"); | |
httpsURLConnection.setDoOutput(true); | |
httpsURLConnection.setDoInput(true); | |
OutputStream outputStream = httpsURLConnection.getOutputStream(); | |
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); | |
String post_data = URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&" | |
+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8"); | |
bufferedWriter.write(post_data); | |
bufferedWriter.flush(); | |
bufferedWriter.close(); | |
outputStream.close(); | |
InputStream inputStream = httpsURLConnection.getInputStream(); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); | |
String result = "", line = ""; | |
while ((line = bufferedReader.readLine()) != null){ | |
result += line; | |
} | |
bufferedReader.close(); | |
inputStream.close(); | |
httpsURLConnection.disconnect(); | |
return result; | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
else if (type.equals("register")){ | |
try { | |
String name = voids[1]; | |
String surname = voids[2]; | |
String age = voids[3]; | |
String username = voids[4]; | |
String password = voids[5]; | |
URL url = new URL(register_url); | |
// register url link is "https" link | |
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection(); | |
httpsURLConnection.setRequestMethod("POST"); | |
httpsURLConnection.setDoOutput(true); | |
httpsURLConnection.setDoInput(true); | |
OutputStream outputStream = httpsURLConnection.getOutputStream(); | |
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); | |
String post_data = URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&" | |
+URLEncoder.encode("surname","UTF-8")+"="+URLEncoder.encode(surname,"UTF-8")+"&" | |
+URLEncoder.encode("age","UTF-8")+"="+URLEncoder.encode(age,"UTF-8")+"&" | |
+URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&" | |
+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8"); | |
bufferedWriter.write(post_data); | |
bufferedWriter.flush(); | |
bufferedWriter.close(); | |
outputStream.close(); | |
InputStream inputStream = httpsURLConnection.getInputStream(); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); | |
String result = "", line = ""; | |
while ((line = bufferedReader.readLine()) != null){ | |
result += line; | |
} | |
bufferedReader.close(); | |
inputStream.close(); | |
httpsURLConnection.disconnect(); | |
return result; | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
else if (type.equals("update")){ | |
try { | |
String id = voids[1]; | |
String name = voids[2]; | |
String surname = voids[3]; | |
String age = voids[4]; | |
String username = voids[5]; | |
String password = voids[6]; | |
URL url = new URL(update_url); | |
// update url link is "http" link | |
HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection(); | |
httpsURLConnection.setRequestMethod("POST"); | |
httpsURLConnection.setDoOutput(true); | |
httpsURLConnection.setDoInput(true); | |
OutputStream outputStream = httpsURLConnection.getOutputStream(); | |
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); | |
String post_data = URLEncoder.encode("id","UTF-8")+"="+URLEncoder.encode(id,"UTF-8")+"&" | |
+URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&" | |
+URLEncoder.encode("surname","UTF-8")+"="+URLEncoder.encode(surname,"UTF-8")+"&" | |
+URLEncoder.encode("age","UTF-8")+"="+URLEncoder.encode(age,"UTF-8")+"&" | |
+URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&" | |
+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8"); | |
bufferedWriter.write(post_data); | |
bufferedWriter.flush(); | |
bufferedWriter.close(); | |
outputStream.close(); | |
InputStream inputStream = httpsURLConnection.getInputStream(); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); | |
String result = "", line = ""; | |
while ((line = bufferedReader.readLine()) != null){ | |
result += line; | |
} | |
bufferedReader.close(); | |
inputStream.close(); | |
httpsURLConnection.disconnect(); | |
return result; | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
else if (type.equals("delete")){ | |
try { | |
String id = voids[1]; | |
URL url = new URL(deleted_url); | |
// delete url link is "http" link | |
HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection(); | |
httpsURLConnection.setRequestMethod("POST"); | |
httpsURLConnection.setDoOutput(true); | |
httpsURLConnection.setDoInput(true); | |
OutputStream outputStream = httpsURLConnection.getOutputStream(); | |
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); | |
String post_data = URLEncoder.encode("id","UTF-8")+"="+URLEncoder.encode(id,"UTF-8"); | |
bufferedWriter.write(post_data); | |
bufferedWriter.flush(); | |
bufferedWriter.close(); | |
outputStream.close(); | |
InputStream inputStream = httpsURLConnection.getInputStream(); | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); | |
String result = "", line = ""; | |
while ((line = bufferedReader.readLine()) != null){ | |
result += line; | |
} | |
bufferedReader.close(); | |
inputStream.close(); | |
httpsURLConnection.disconnect(); | |
return result; | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
return null; | |
} | |
@Override | |
protected void onPreExecute() { | |
alertDialog = new AlertDialog.Builder(context).create(); | |
alertDialog.setTitle("Server Alert"); | |
} | |
@Override | |
protected void onPostExecute(String result) { | |
alertDialog.setMessage(result); | |
alertDialog.show(); | |
} | |
@Override | |
protected void onProgressUpdate(Void... values) { | |
super.onProgressUpdate(values); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
public class MainActivity extends Activity{ | |
EditText user_name, pass; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
user_name = (EditText)findViewById(R.id.user_name); | |
pass = (EditText)findViewById(R.id.pass); | |
} | |
public void login_user(View view){ | |
String userName = user_name.getText().toString(); | |
String userPass = pass.getText().toString(); | |
String type = "login"; | |
BackgroundWorker backgroundWorker = new BackgroundWorker(this); | |
backgroundWorker.execute(type, userName,userPass); | |
} | |
public void go_to_register(View view){ | |
startActivity(new Intent(MainActivity.this, Register.class)); | |
} | |
public void show_data(View view){ | |
startActivity(new Intent(MainActivity.this, Show_Data.class)); | |
} | |
public void update_data(View view){ | |
startActivity(new Intent(MainActivity.this, Update_Data.class)); | |
} | |
public void delete_data(View view){ | |
startActivity(new Intent(MainActivity.this, Delete_Data.class)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.sharifulislam.potest.MainActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:padding="10dp"> | |
<EditText | |
android:id="@+id/user_name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/username"/> | |
<EditText | |
android:id="@+id/pass" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/password"/> | |
<Button | |
android:onClick="login_user" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/login" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
<Button | |
android:onClick="go_to_register" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/register" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
<Button | |
android:onClick="show_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/show_data" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
<Button | |
android:onClick="update_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/updaet" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
<Button | |
android:onClick="delete_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/delete" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
</LinearLayout> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
public class Register extends AppCompatActivity { | |
EditText name, surname, age, user_name, pass; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_register); | |
// cast area | |
name = (EditText)findViewById(R.id.name); | |
surname = (EditText)findViewById(R.id.surname); | |
age = (EditText)findViewById(R.id.age); | |
user_name = (EditText)findViewById(R.id.user_name); | |
pass = (EditText)findViewById(R.id.pass); | |
} | |
public void register_user(View view){ | |
String name_t = name.getText().toString(); | |
String surname_t = surname.getText().toString(); | |
String age_t = age.getText().toString(); | |
String userName = user_name.getText().toString(); | |
String userPass = pass.getText().toString(); | |
String type = "register"; | |
BackgroundWorker backgroundWorker = new BackgroundWorker(this); | |
backgroundWorker.execute(type, name_t, surname_t, age_t, userName, userPass); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.sharifulislam.potest.Register"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:padding="10dp"> | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/name"/> | |
<EditText | |
android:id="@+id/surname" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/surname"/> | |
<EditText | |
android:id="@+id/age" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/age"/> | |
<EditText | |
android:id="@+id/user_name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/username"/> | |
<EditText | |
android:id="@+id/pass" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/password"/> | |
<Button | |
android:onClick="register_user" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/register" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
</LinearLayout> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
public class Update_Data extends AppCompatActivity { | |
EditText id, name, surname, age, user_name, pass; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_update__data); | |
// cast area | |
id = (EditText)findViewById(R.id.id); | |
name = (EditText)findViewById(R.id.name); | |
surname = (EditText)findViewById(R.id.surname); | |
age = (EditText)findViewById(R.id.age); | |
user_name = (EditText)findViewById(R.id.user_name); | |
pass = (EditText)findViewById(R.id.pass); | |
} | |
public void update_data(View view){ | |
String id_t = id.getText().toString(); | |
String name_t = name.getText().toString(); | |
String surname_t = surname.getText().toString(); | |
String age_t = age.getText().toString(); | |
String userName = user_name.getText().toString(); | |
String userPass = pass.getText().toString(); | |
String type = "update"; | |
BackgroundWorker backgroundWorker = new BackgroundWorker(this); | |
backgroundWorker.execute(type, id_t, name_t, surname_t, age_t, userName, userPass); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.sharifulislam.potest.Update_Data"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:padding="10dp"> | |
<EditText | |
android:id="@+id/id" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/id"/> | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/name"/> | |
<EditText | |
android:id="@+id/surname" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/surname"/> | |
<EditText | |
android:id="@+id/age" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/age"/> | |
<EditText | |
android:id="@+id/user_name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/username"/> | |
<EditText | |
android:id="@+id/pass" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/password"/> | |
<Button | |
android:onClick="update_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/updaet" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
</LinearLayout> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
public class Delete_Data extends AppCompatActivity { | |
EditText data_id; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_delete__data); | |
data_id = (EditText)findViewById(R.id.data_id); | |
} | |
public void delete_data(View view){ | |
String id_t = data_id.getText().toString(); | |
String type = "delete"; | |
BackgroundWorker backgroundWorker = new BackgroundWorker(this); | |
backgroundWorker.execute(type, id_t); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.sharifulislam.potest.Delete_Data" | |
android:orientation="vertical" | |
android:padding="10dp"> | |
<EditText | |
android:id="@+id/data_id" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/password"/> | |
<Button | |
android:onClick="delete_data" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/delete" | |
android:textColor="@color/colorPrimary" | |
android:textSize="20sp"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sharifulislam.potest; | |
import android.os.StrictMode; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import org.json.JSONArray; | |
import org.json.JSONObject; | |
import java.io.BufferedInputStream; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
public class Show_Data extends AppCompatActivity { | |
String server_link = "http://your_domain_name/get_data.php"; | |
InputStream inputStream = null; | |
String line = null, result = null; | |
EditText input_text; | |
TextView show_output; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_show__data); | |
input_text = (EditText)findViewById(R.id.input_text); | |
show_output = (TextView)findViewById(R.id.show_output); | |
} | |
public void ok_done(View view){ | |
String passing_data = input_text.getText().toString(); | |
// allow network in main thread | |
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitNetwork().build()); | |
// retrieve | |
String data = get_data(server_link, "name", passing_data, ","); | |
show_output.setText(data); | |
} | |
public String get_data(String link, String column_name, String pass_data, String splite_data_by){ | |
String get_data[]; | |
StringBuffer return_string = new StringBuffer(); | |
try { | |
String new_link = link+"?data_from_app="+pass_data; | |
URL url = new URL(new_link); | |
HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection(); | |
httpsURLConnection.setRequestMethod("GET"); | |
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream()); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// read input stream into a string | |
try{ | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | |
StringBuilder stringBuilder = new StringBuilder(); | |
while ((line = bufferedReader.readLine()) != null){ | |
stringBuilder.append(line + "\n"); | |
} | |
inputStream.close(); | |
result = stringBuilder.toString(); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
// Parse json data | |
try{ | |
JSONArray jsonArray = new JSONArray(result); | |
JSONObject jsonObject = null; | |
get_data = new String[jsonArray.length()]; | |
for (int i=0; i<jsonArray.length(); i++){ | |
jsonObject = jsonArray.getJSONObject(i); | |
get_data[i] = jsonObject.getString(column_name); // column name | |
} | |
for (int j=0; j<get_data.length; j++){ | |
if (j==0){ | |
return_string.append(get_data[j]); | |
} | |
else { | |
return_string.append(get_data[j]+splite_data_by); | |
} | |
} | |
} | |
catch (Exception e){ | |
e.printStackTrace(); | |
} | |
return return_string.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.sharifulislam.potest.Show_Data" | |
android:orientation="vertical"> | |
<EditText | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/input_text"/> | |
<Button | |
android:onClick="ok_done" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/show_data"/> | |
<TextView | |
android:id="@+id/show_output" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/app_name" | |
android:textSize="20sp"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.sharifulislam.potest"> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
" | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity | |
android:name=".Register" | |
android:parentActivityName=".MainActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value=".MainActivity" /> | |
</activity> | |
<activity | |
android:name=".Show_Data" | |
android:parentActivityName=".MainActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value=".MainActivity" /> | |
</activity> | |
<activity | |
android:name=".Update_Data" | |
android:parentActivityName=".MainActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value=".MainActivity" /> | |
</activity> | |
<activity android:name=".Delete_Data" | |
android:parentActivityName=".MainActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value=".MainActivity" /> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name">PO Test</string> | |
<string name="username">username</string> | |
<string name="password">password</string> | |
<string name="name">Name</string> | |
<string name="surname">Surname</string> | |
<string name="age">Age</string> | |
<string name="login">Login</string> | |
<string name="register">Register</string> | |
<string name="show_data">Show Data</string> | |
<string name="updaet">Update</string> | |
<string name="id">ID</string> | |
<string name="delete">Delete</string> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db_name = "database_name"; | |
$mysql_username = "mysql_username"; | |
$mysql_password = "mysql_password"; | |
$server_name = "localhost"; | |
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name); | |
/* | |
if ($conn) { | |
echo "connection success!"; | |
} | |
else{ | |
echo "connection not success!"; | |
} | |
*/ | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "conn.php"; | |
$user_naem = $_POST["username"]; | |
$user_pass = $_POST["password"]; | |
$mysql_qry = "select * from android_data where username like '$user_naem' and password like '$user_pass';"; | |
$result = mysqli_query($conn, $mysql_qry); | |
if (mysqli_num_rows($result)>0) { | |
$row = mysqli_fetch_assoc($result); | |
$name = $row["username"]; | |
echo "login success! Welcome " .$name; | |
} | |
else{ | |
echo "login faile!"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "conn.php"; | |
$name = $_POST["name"]; | |
$surname = $_POST["surname"]; | |
$age = $_POST["age"]; | |
$username = $_POST["username"]; | |
$password = $_POST["password"]; | |
$mysql_qry = "insert into android_data (name, surname, age, username, password) values ('$name', '$surname', '$age', '$username', '$password')"; | |
if ($conn->query($mysql_qry) === TRUE) { | |
echo "Insert Successful"; | |
} | |
else{ | |
echo "Error : " . $mysql_qry . "<br>" . $conn->error; | |
} | |
$conn->close(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "conn.php"; | |
$id = $_POST["id"]; | |
$name = $_POST["name"]; | |
$surname = $_POST["surname"]; | |
$age = $_POST["age"]; | |
$username = $_POST["username"]; | |
$password = $_POST["password"]; | |
// Select Database | |
mysqli_select_db($conn, "id4931910_android1"); | |
// update query | |
$sql = "update android_data set name='$name', surname='$surname',age='$age', username='$username', password='$password' where id='$id'"; | |
// Execuet query | |
if (mysqli_query($conn,$sql)) { | |
echo "update successfully!"; | |
} | |
else{ | |
echo "not update data."; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "conn.php"; | |
$id = $_POST["id"]; | |
// Select Database | |
mysqli_select_db($conn, "id4931910_android1"); | |
// update query | |
$sql = "delete from android_data where id='$id'"; | |
// Execuet query | |
if (mysqli_query($conn,$sql)) { | |
echo "delete successfully!"; | |
} | |
else{ | |
echo "not delete data."; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "conn.php"; | |
$user_name = $_GET["data_from_app"]; | |
$query = mysqli_query($conn, "select * from android_data where username='$user_name'"); | |
if ($query) { | |
while ($row = mysqli_fetch_array($query)) { | |
$flag[] = $row; | |
} | |
print(json_encode($flag)); | |
} | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment