2016-09-15 69 views
0

得到的字符串我有这样的应用程序,我使用PHP和MySQL我在Android Studio中的查询,但在使用更新即时它不工作的PHP应该给我的$result什么串给我,但它不是给它的空白。的Android PostResponseAsyncTask不能在Android

这是我的代码。

的Android

HashMap postData = new HashMap(); 

    if (TextUtils.isEmpty(etCarModel.getText().toString())) { 
     Toast.makeText(UpdateClick.this, "Car model is empty", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    if (TextUtils.isEmpty(etCarType.getText().toString())) { 
     Toast.makeText(UpdateClick.this, "Car type is empty", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    if (TextUtils.isEmpty(etCapacity.getText().toString())) { 
     Toast.makeText(UpdateClick.this, "Capacity is empty", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    if (TextUtils.isEmpty(etPlateNumber.getText().toString())) { 
     Toast.makeText(UpdateClick.this, "Plate Number is empty", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    if (TextUtils.isEmpty(etPrice.getText().toString())) { 
     Toast.makeText(UpdateClick.this, "Price is empty", Toast.LENGTH_SHORT).show(); 
     return; 
    } 
    postData.put("txtCar_No", tvCar_No.getText().toString()); 
    postData.put("txtCarModel", etCarModel.getText().toString()); 
    postData.put("txtCarType", etCarType.getText().toString()); 
    postData.put("txtCapacity", etCapacity.getText().toString()); 
    postData.put("txtPlateNumber", etPlateNumber.getText().toString()); 
    postData.put("txtCarPrice", etPrice.getText().toString()); 
    postData.put("image", toString()); 
    postData.put("txtFuelType", spFuelType.getSelectedItem().toString()); 

    PostResponseAsyncTask taskUpdate = new PostResponseAsyncTask(UpdateClick.this, postData, new AsyncResponse() { 
     @Override 
     public void processFinish(String q) { 
      Log.d(TAG,q); 
      if(q.contains("success")){ 
       Toast.makeText(UpdateClick.this, "Car details updated!", Toast.LENGTH_SHORT).show(); 
       Intent in = new Intent(UpdateClick.this, OwnerTabs.class); 
       startActivity(in); 
       finish(); 
      }else{ 
       Toast.makeText(getApplicationContext(), "Error ? " + q.toString(), Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 
    taskUpdate.execute("http://carkila.esy.es/update.php"); 
} 

PHP

<?php 
include_once("connection.php"); 

if(isset($_POST['txtCar_No']) && isset($_POST['txtCarModel']) && 
isset($_POST['txtCarType']) && isset($_POST['txtCapacity']) && 
isset($_POST['image']) && isset($_POST['txtFuelType']) && 
isset($_POST['txtPlateNumber']) && isset($_POST['txtcarPrice'])) 
{ 
$now = DateTime::createFromFormat('U.u', microtime(true)); 
$id = $now->format('YmdHis'); 

$upload_folder = "upload"; 
$path = "$upload_folder/$id.jpeg"; 
$fullpath = "http://carkila.esy.es/$path"; 

$image = $_POST['image']; 
$Car_No = $_POST['txtCar_No']; 
$Car_Model = $_POST['txtCarModel']; 
$Car_Type = $_POST['txtCarType']; 
$Capacity = $_POST['txtCapacity']; 
$Fuel_Type = $_POST['txtFuelType']; 
$PlateNumber = $_POST['txtPlateNumber']; 
$carPrice = $_POST['carPrice']; 

$query = "UPDATE tbl_cars SET Car_Model='$Car_Model', Car_Type='$Car_Type', Capacity='$Capacity', Image='$fullpath', fuelType='$Fuel_Type',carPlatenuNumber='$PlateNumber' ,carPrice= '$carPrice' WHERE 'Car_No'=$Car_No"; 

$result = mysqli_query($conn,$query); 
$count = mysqli_affected_rows($conn); 

if($result == TRUE && $count > 0){ 
echo "success"; 
exit(); 
}else{ 
print_r (mysqli_error($conn)); 
echo "failed"; 
exit(); 
} 
} 
?> 

回答

0

我是从移动,而是试图改变$结果

$result = mysqli_query($conn,$query); 

有了这个:

$result = mysqli_query($conn,$query) or die(mysqli_error($conn)); 

编辑:

你必须检查的信息是否被发送,所以尽量把它插入到你的代码:

$filename = "log.txt"; 
$fh   = fopen($filename, "a") or die("Could not open log file."); 
$post  = var_dump($post); 
fwrite($fh, date("d-m-Y, H:i")." - $post\n") or die("Could not write file!"); 
fclose($fh); 

不要忘记创建一个log.txt文件使用chmod 777

+0

我在哪里可以创建一个log.txt的其新的给我,先生,我会在我的文件管理器?我现在使用在线虚拟主机。谢谢:) – Jengjeng

+0

我会把'$ Car_No'上的单引号,即使它是我的分贝整数? – Jengjeng

+0

如果它是一个你不需要的整数。我编辑了我的答案 – ramirez