i have problem in my app i have a users table in my database with 3 columns, now i want to get the user registering time from my database(server) and send to my app, and it showed in user profile(as dialog) in the app. its my php code :
function get(){
$connection = connectToDatabase();
$Username = $_REQUEST['Username'];
$Pass = $_REQUEST['Pass'];
if($Username!="" && $Pass!=""){
$result = mysqli_query($connection,"select Date from users where Username='$Username' and Pass='$Pass');
$array_finish = array();
while($row = mysqli_fetch_array($result)){
$record = array();
$record['Date'] = $row['Date'];
$array_finish[] = $record ;
}
echo json_encode($array_finish);
}else {
print "null";
}
mysqli_close($connection); }
but i have some error in this codes and i dont know how i can get this information in my app. i know my codes in android isn't correct it's my android codes:
private void ShowProfile(){
profile = new MaterialDialog.Builder(MainActivity.this)
.customView(R.layout.alert_aprofile,false)
.show();
AsyncHttpPost post = new AsyncHttpPost(
"http://********/profile.php"
);
post.setTimeout(5000);
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("Username",sp.getString("Username", null));
body.addStringPart("Pass",sp.getString("Pass", null));
post.setBody(body);
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(final Exception e, AsyncHttpResponse source, final String row) {
if (e != null) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
wait.dismiss();
Toast.makeText(MainActivity.this, "no connection", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
});
}
if (!row.equals("")) {
profile_time = (TextView)profile.findViewById(R.id.profile_time);
profile_time.setText(row);
}else if(row.equals("null")){
runOnUiThread(new Runnable() {
@Override
public void run() {
wait.dismiss();
;
}
});
}
}
});
please help me to correcting that..
i edit android code to new code but i know it isnt correct and dont work...
private void ShowProfile(){
profile = new MaterialDialog.Builder(MainActivity.this)
.customView(R.layout.alert_aprofile,false)
.show();
AsyncHttpPost post = new AsyncHttpPost(
"http://****************profile.php"
);
post.setTimeout(5000);
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("Username",sp.getString("Username", null));
body.addStringPart("Pass",sp.getString("Pass", null));
post.setBody(body);
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(final Exception e, AsyncHttpResponse source, final String result) {
if (e != null) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
wait.dismiss();
Toast.makeText(MainActivity.this, "no connection", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
});
}
if (!result.equals("")) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
items.clone();
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
HashMap<String, Object> hash_add = new HashMap<String, Object>();
hash_add.put("Date", object.getString("Date"));
hash_all.add(hash_add);
items = new String[hash_all.size()];
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
});