I want to edit the database values from android studio. My table consists of ("id","name","username","email","age","password", here is my php code which will upload the info to database, but i want to change the password how can i edit my code so that the particular data in "password" column is erased and replaced with the new "password".
My php code:
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $id, $name, $username, $email, $age, $password);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["username"] = $username;
$response["email"]= $email;
$response["age"] = $age;
$response["password"] = $password;
}
echo json_encode($response);
?>
and here is my MainActivity code:
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
public class RegisterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
final EditText etAge = (EditText) findViewById(R.id.etAge);
final EditText etName = (EditText) findViewById(R.id.etName);
final EditText etUsername = (EditText) findViewById(R.id.etUsername);
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
final Button bRegister = (Button) findViewById(R.id.bRegister);
final EditText etEmail=(EditText) findViewById(R.id.etEmail);
assert bRegister != null;
assert bRegister != null;
bRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
assert etName != null;
final String name = etName.getText().toString();
assert etUsername != null;
final String username = etUsername.getText().toString();
assert etAge != null;
final String age = etAge.getText().toString();
assert etPassword != null;
final String password = etPassword.getText().toString();
assert etEmail != null;
final String email = etEmail.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
private ProgressDialog loading;
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
loading = ProgressDialog.show(RegisterActivity.this, "Please wait...", "Registering...", false, false);
if (success) {
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
RegisterActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(name, username, email, age, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
}
});
}
UPDATE user SET Password = Whateveryournewpasswordis where username=yourusernameand in the Android create an activity and pass the new password via HashMaps and JSonObjectRequest(not necessarily). This is the shorter version. Follow the SQL injection prevention you have used earlier :)