我的应用有问题 我的数据库中有3列用户表,现在我想从数据库(服务器)获取用户的注册时间并发送到我的应用程序,该表显示在应用程序的用户个人资料(作为对话框)中。 它是我的PHP代码:
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); }
但是我在此代码中有一些错误,我不知道如何在我的应用程序中获取此信息。我知道我在android中的代码不正确 这是我的android代码:
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();
;
}
});
}
}
});
请帮助我纠正该问题。
我将android代码编辑为新代码 但我知道这是不正确的,并且不起作用...
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();
}
}
});
}
}
});