2016-09-15 10 views
0

私はアンドロイドスタジオで私のクエリにPHPとMysqlを使用していますが、私がアップデートを使用しているときにPHPが動かない場合は$resultが私に与える文字列を教えてください空白を与える。Android PostResponseAsyncTask cantはアンドロイドから文字列を取得します

これは私のコードです。

アンドロイド

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); 

EDIT:

$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); 

いけないのchmod 777でlog.txtファイルを作成するのを忘れ:

あなたは情報が送られているかどうかを確認するため、あなたのコードにそれを挿入しようとしなければなりません

+0

どこにlog.txtを作成することができますか?私はファイルマネージャに入れますか?今オンラインウェブホストを使用しています。ありがとう:) – Jengjeng

+0

私は '$ Car_No'に一重引用符を入れても、その整数は私のデータベースに? – Jengjeng

+0

整数であれば、必要はありません。私は私の答えを – ramirez

関連する問題