Sei sulla pagina 1di 3

?????????????????????????????????

API
<?php
error_reporting(E_ALL ^ E_DEPRECATED);

$servername="localhost";
$username="id7989663_akshay";
$password="akshay";
$dbname="id7989663_user_db";

$conn=mysqli_connect($servername,$username,$password,$dbname);
if(!$conn){
echo"Database Not Connected";
}

$uname=$_GET['email'];
$password=$_GET['password'];

if (!empty($_GET))
{
if (empty($_GET['email']) || empty($_GET['password']))
{
$response["success"] = 0;
$response["message"] = "One or both of the fields are empty ....";
die(json_encode($response));

$query="select * from user where email='$uname' and password='$password'";


$res=mysqli_query($conn,$query);
$count=mysqli_num_rows($res);

if($count>0){
$response["success"] = 1;
$response["message"] = "You have been
sucessfully login";
die(json_encode($response));

}
else{
$response["success"] = 0;
$response["message"] = "invalid userid or password ";
die(json_encode($response));
}

else
{
$response["success"] = 0; $response["message"] = " One or both of the fields are
empty ";
die(json_encode($response));
}
mysqli_close();
?>

??????????????????????????????????

final String gmail=emailText.getText().toString().trim();


final String password=passwordText.getText().toString().trim();
StringRequest stringRequest = new
StringRequest(Request.Method.POST, "https://abvgietcis.000webhostapp.com/login.php?
email=" + gmail + "&password=" + password,

new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(Login.this, response,
Toast.LENGTH_LONG).show();
try {
System.out.println("+++++++++++++++++++++++++++
++++" + response.toString());
JSONObject oo = new
JSONObject(response.toString());
String res = oo.optString("success");
// String msg = oo.optString("message");
if (res.equals("1")) {
System.out.println("Message****" + res);
// System.out.println("Message****"+msg);
// JSONArray contacts =
oo.getJSONArray("response");
Toast.makeText(getApplicationContext(),
"valid Login", Toast.LENGTH_SHORT).show();

// Intent i = new Intent(loginpage.this,


homepage.class);
// i.putExtra("email",gmail);
//startActivity(i);
finish();
} else {
// progressDialog.dismiss();
Toast.makeText(getApplicationContext(),
"Login Failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {

Toast.makeText(Login.this, "Login Error",


Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
error.toString(), Toast.LENGTH_LONG).show();

}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("email",gmail );
params.put("password", password);
return params;
}
};
RequestQueue requestQueue =
Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);

Potrebbero piacerti anche