ログインアプリでログインすると、ログイン後に電子メールとパスワードが共有設定に保存されます。次に、ユーザは、作業に利用可能であることを意味するボタンを「チェック」しなければならない第2の活動に持ち込まれる。VolleyのPOSTリクエストを使用してMySQLフィールドを更新パラメータとして共有設定で
私はSQLデータベースのフィールドを更新するためのパラメータとして電子メールアドレスと文字列 "available"を送信しようとしています。
だから私は別のクラスで定義されているカップルの定数を持っている:
Config.java
//Currently logged in employee
public static final String EMAIL_SHARED_PREF = "employee_email";
//URL to PHP file that updates the field
public static final String EMPLOYEE_STATUS_URL = "http://localhost/android/employeestatus.php";
私は、SQLフィールドを更新するためにPOST要求を行い、私の活動の方法があります:
CheckinActivity.java
private void checkin() {
SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
final String employee_email = sharedPreferences.getString(Config.EMAIL_SHARED_PREF,"Not Available");
final String employee_status = "available";
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.EMPLOYEE_STATUS_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(CheckinActivity.this, response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(CheckinActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("employee_status", employee_status);
params.put("employee_email", employee_email);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
とリクエストを処理し、最後にPHPファイル:
employeestatus.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$employee_email = $_POST['employee_email'];
$employee_status = $_POST['employee_status'];
//importing database connection script
require_once('dbConnect.php');
//Creating sql query
$sql = "UPDATE employees
SET employee_status = '$employee_status'
WHERE employee_email = '$employee_email'";
//Updating database table
if (mysqli_query($conn,$sql)) {
echo 'Status Updated';
}
else {
echo 'Status Not Updated';
}
//closing connection
mysqli_close($conn);
}
{ print_r($_POST); return; }
それが今であるため、ALL列だけではなく、従業員の利用可能を示すためにアップデートをフィールド誰がアプリにログインしていますか。何か案は?
EDIT
私のオリジナルの試みは、私がメールアドレスを投稿しようとしていた部分は明らかに間違っていました。 employee_status
フィールドを更新するだけで済みますが、SQL UPDATEのWHEREになるように、アプリケーションからの共有設定メールが必要です。
私はURLに電子メールを添付してGET値として割り当てることができたが、うまくいかないと思った。うーん、まだそれに取り組んで...