Data Insert and Data Update With Delete Connection MYSQL

 DFDDDDDDD


<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ServerDeletEditShow">

<LinearLayout
android:id="@+id/tvtv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.cardview.widget.CardView
android:id="@+id/loginBoard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
app:cardCornerRadius="30dp"
app:cardElevation="20dp"
android:background="@drawable/custom_edittext">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Your Data "
android:id="@+id/loginText"
android:textSize="20sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/purple"/>
<TextView
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@color/purple"
android:inputType="numberDecimal"
android:layout_height="wrap_content"
android:text="Type Your Name ?"/>

<EditText
android:id="@+id/edName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textPersonName"
android:padding="10dp"
android:hint="Type Your Name ?"
android:drawablePadding="8dp"
android:layout_marginTop="5dp"
android:background="@drawable/custom_edittext"/>

<TextView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@color/purple"
android:layout_height="wrap_content"
android:text="Type Your Mobile number?"/>
<EditText
android:id="@+id/edMobile"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="number"
android:padding="10dp"
android:hint="Type Your Mobile number"
android:drawablePadding="8dp"
android:layout_marginTop="5dp"
android:background="@drawable/custom_edittext"/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@color/purple"
android:layout_height="wrap_content"
android:text="Type Your Address?"/>
<EditText
android:id="@+id/edAdress"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="text"
android:padding="10dp"
android:hint="Type Your Address"
android:drawablePadding="8dp"
android:layout_marginTop="5dp"
android:background="@drawable/custom_edittext"/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@color/purple"
android:layout_height="wrap_content"
android:text="Type Your Email?"/>
<EditText
android:id="@+id/edEmail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textEmailAddress"
android:padding="10dp"
android:hint="Type Your Email"
android:drawablePadding="8dp"
android:layout_marginTop="5dp"
android:background="@drawable/custom_edittext"/>
<Button
android:id="@+id/sSaveButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="SAVE DATA "
android:layout_weight="1"
android:padding="10dp"
android:drawablePadding="8dp"
android:layout_marginTop="20dp"
android:background="@drawable/custom_edittext"/>

<ListView
android:id="@+id/tvListView"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

</androidx.cardview.widget.CardView>



</ScrollView>
</LinearLayout>
</LinearLayout>

JAVA  

package com.example.apiseassion;

import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class ServerDeletEditShow extends AppCompatActivity {
EditText edName, edMobile, edAdress, edEmail;
ProgressBar progressBar;
Button sSaveButton;
// data show listview
ListView tvListView;
ArrayList<HashMap<String,String>> arrayList=new ArrayList<>();
HashMap<String,String> hashMap;

//
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_server_delet_edit_show);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
//mmmmmmmmmmmmmmmmmmm
edName = findViewById(R.id.edName);
edMobile = findViewById(R.id.edMobile);
edAdress = findViewById(R.id.edAdress);
edEmail = findViewById(R.id.edEmail);
progressBar=findViewById(R.id.progressBar);
sSaveButton=findViewById(R.id.sSaveButton);
//list view
tvListView=findViewById(R.id.tvListView);
loadData();
//// list view show


///////////list view sesh work






//..............manin data Insert
sSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String name = edName.getText().toString();
String mobile = edMobile.getText().toString();
String email = edEmail.getText().toString();
String address = edAdress.getText().toString();
String url = "http://192.168.1.3//Apps/urldatainsertdatabase.php?name=" + name + "&mobile=" + mobile + "&email=" + email + "&address=" + address;



StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage(response)
.show();
loadData();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage("Dident work")
.show(); }
});

// Add the request to the RequestQueue.
if (name.length() >0&&mobile.length()<=11&&email.length()>0&&address.length()>0) {
RequestQueue queue = Volley.newRequestQueue(ServerDeletEditShow.this);
queue.add(stringRequest);
}else{ edAdress.setError("Please Imput Your Type");
edName.setError("Please Imput Your Type");
edMobile.setError("Please Imput Your Type 11 digit number");
edEmail.setError("Please Imput Your Type");

}




}


});



//llllllllllllllllllllllllllllllllllll

//lllllllllllllllllllllllll
}

//adapter

public class ListshowAdapter extends BaseAdapter {
@Override
public int getCount() {
return arrayList.size();
}

@Override
public Object getItem(int i) {
return null;
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater layoutInflater = getLayoutInflater();
View myView = layoutInflater.inflate(R.layout.item, null);
TextView tvId = myView.findViewById(R.id.tvId);
TextView tvName = myView.findViewById(R.id.tvName);
TextView tvNumber = myView.findViewById(R.id.tvNumber);
TextView tvemail = myView.findViewById(R.id.tvEmail);
TextView tvaddress = myView.findViewById(R.id.tvAddress);
Button updateButton=myView.findViewById(R.id.updateButton);
Button tvDeletbutton=myView.findViewById(R.id.deleteButton);


HashMap<String, String> hashMap = arrayList.get(i);
String id = hashMap.get("id");
String mobile = hashMap.get("mobile");
String name = hashMap.get("name");
String email = hashMap.get("email");
String address = hashMap.get("address");

tvId.setText(id);
tvName.setText(name);
tvNumber.setText(mobile);
tvemail.setText(email);
tvaddress.setText(address);

updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String name = edName.getText().toString();
String mobile = edMobile.getText().toString();
String email = edEmail.getText().toString();
String address = edAdress.getText().toString();
String url = "http://192.168.1.3//Apps/update.php?id="+id+"&name="+name+"&mobile="+mobile+"&email="+email+"&address="+address;
progressBar.setVisibility(View.VISIBLE);

sSaveButton.setVisibility(View.GONE);

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressBar.setVisibility(View.GONE);
// Display the first 500 characters of the response string.
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage(response)
.show();
loadData();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("updateRequest",error.toString());
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage("Didn't work")
.show(); }
});

// Add the request to the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(ServerDeletEditShow.this);
queue.add(stringRequest);

}
});
tvDeletbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "http://192.168.1.3//Apps/delete.php?id="+id;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage(response)
.show();
loadData();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("updateRequest",error.toString());
new AlertDialog.Builder(ServerDeletEditShow.this)
.setTitle("Server Response")
.setMessage("Didn't work")
.show(); }
});

// Add the request to the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(ServerDeletEditShow.this);
queue.add(stringRequest);


}
});


// String video_id=hasmap.get("video_id");
// String image="https://img.youtube.com/vi/"+video_id+"/0.jpg";
// https://img.youtube.com/vi/wwSiTbIn92Q/0.jpg
// Picasso.get()
// .load(image)
// .placeholder(R.drawable.img)
// .into(ImageViw);

return myView;
}
}
//adapter
//Load data start

private void loadData(){
arrayList=new ArrayList<>();
RequestQueue queue = Volley.newRequestQueue(ServerDeletEditShow.this);
String url = "http://192.168.1.3//Apps/dataanadatabasetheke.php";

JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url,null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
progressBar.setVisibility(View.GONE);
Log.d("ResponseRes","response");

// Display the first 500 characters of the response string.
try {
for (int x=0; x<response.length(); x++) {
JSONObject jsonObject = response.getJSONObject(x);
String id = jsonObject.getString("id");
String name = jsonObject.getString("name");
String mobile = jsonObject.getString("mobile");
String email =jsonObject.getString("email");
String address =jsonObject.getString("address");

hashMap=new HashMap<>();
hashMap.put("id",id);
hashMap.put("name",name);
hashMap.put("email",email);
hashMap.put("mobile",mobile);
hashMap.put("address",address);
arrayList.add(hashMap);
}
ListshowAdapter listshowAdapter=new ListshowAdapter();
tvListView.setAdapter(listshowAdapter);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressBar.setVisibility(View.VISIBLE);

}
});

// Add the request to the RequestQueue.
queue.add(jsonArrayRequest);

}
//load data end


}

Create Itemdesign_item.xml List View a R jonno korte hobe 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_shade"
android:orientation="horizontal"
android:weightSum="10">

<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="left"
android:hint="music 01 "
android:src="@drawable/musicplay" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_weight="8"
android:orientation="vertical">
<TextView
android:id="@+id/tvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:layout_gravity="center"
android:text="Shaim in Country"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:layout_gravity="center"
android:text="Shaim in Country"
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/tvNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:gravity="center"
android:text="Duration : 5"
android:textSize="20dp"
android:textStyle="italic" />
<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:layout_gravity="center"
android:text="Shaim in Country"
android:textSize="15dp"
android:textStyle="bold" />

<TextView
android:id="@+id/tvAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:gravity="center"
android:text="Duration : 5"
android:textSize="20dp"
android:textStyle="italic" />

</LinearLayout>

<ImageView
android:id="@+id/music01"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="right"
android:hint="music 01 "
android:src="@drawable/musicplay"
android:tag="NOT_PLAYING" />

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2">
<Button
android:id="@+id/updateButton"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Update"/>
<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_weight="1"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:text="Delete"/>
</LinearLayout>

</LinearLayout>



</LinearLayout>

Then Abr API r r jono Sob Code Website a Php ar maddome korte hobe

website or apps connection MYSQL DATA BASE Main Data Apps connection kora


dataanadatabasetheke.php

<?php


$con=mysqli_connect("localhost","root","","my_database");
$sql="SELECT * FROM user_taible ORDER BY id DESC";
$result=mysqli_query($con,$sql);
$rowCount =mysqli_num_rows($result);

//echo "Total Row ".$rowCount."<br><br>";
$data=array();

foreach($result as $item){
    $id=$item['id'];
    $name=$item['name'];
    $mobile=$item['mobile'];
    $email=$item['email'];
    $address=$item['address'];
//echo $id.".".$name."<br>".$mobile."<br>".$email."<br>".$address."<br><br>";
$userinfo['id']=$id;
$userinfo['name']=$name;
$userinfo['mobile']=$mobile;
$userinfo['email']=$email;
$userinfo['address']=$address;
array_push($data,$userinfo);

}

echo json_encode($data);

?>

Update.php


<?php

$namee = $_GET['name'];
    $mobilee =$_GET['mobile'];
    $emaile =$_GET['email'];
    $addresse =$_GET['address'];
    $ide = $_GET['id'];

$con=mysqli_connect("localhost","root","","my_database");
$sql="UPDATE user_taible SET name='$namee',mobile='$mobilee',email='$emaile',address='$addresse' WHERE id='$ide' ";
$result=mysqli_query($con,$sql);
if($result) echo " Successfully insert Update to Database";
else echo "Something Wrong";


//http://192.168.1.3//Apps/update.php?name=ShamimHosen&mobile=01969303276&email=sh98459@gmail.com&address=PabaRajshahi&id=2


?>

Delete.php


<?php


    $id=$_GET['id'];
$con=mysqli_connect("localhost","root","","my_database");
$sql="DELETE FROM user_taible WHERE id='$id' ";


$result=mysqli_query($con,$sql);


if($result) echo  "Successfully Deleteed From Database";
else echo "Something Wrong";






?>

Post a Comment

Previous Post Next Post
Girl in a jacket