Can someone help me to figure out the problem ? I'm new to php
and now trying to send the data from android to MySQL
. I want to update the password based on user's name. I've tried to code but I get error when update button
is clicked.
public void changePassword(final String name, final String password)
{
class UpdateUser extends AsyncTask<Void,Void,String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(ForgetPassword.this,"Updating...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(ForgetPassword.this,s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(Void... params) {
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put(Config.KEY_USER_NAME,name);
hashMap.put(Config.KEY_PASSWORD,password);
RequestHandler rh = new RequestHandler();
String s = rh.sendPostRequest(Config.UPDATE_USER_URL,hashMap);
return s;
}
}
UpdateUser ue = new UpdateUser();
ue.execute();
}
UpdateUser.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$name = $_POST['name'];
$pssword = $_POST['password'];
//importing database connection script
require_once('dbConnect.php');
//Creating sql query
$sql = "UPDATE users SET password = '$password' WHERE name = $name;";
//Updating database table
if(mysqli_query($con,$sql)){
echo ' Updated Successfully';
}else{
echo 'Could Not Update users Try Again';
}
//closing connection
mysqli_close($con);
}
?>
I get message Could Not Update users Try Again
.