私のJavaクラスは、正しい情報を入れて正しいフィールドを呼び出しても、常にelseステートメントに進みます。私を助けてください。アンドロイドのPHP更新クエリはいつも他に行くstatment
以下は私のコードです。 getintents
に問題はなく、どこに問題があるのかわかりません。
update.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";
$image = $_POST['image'];
$fullpath = "http://carkila.esy.es/$upload_folder/$id.jpeg";
$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', fuelType='$Fuel_Type' ,carPlatenuNumber='$PlateNumber', image='$fullpath' , carPrice = '$carPrice' WHERE Car_No='$Car_No'";
$result = mysqli_query($conn,$query);
if($result > 0){
echo "success";
exit;
}
else{
echo"failed";
exit;
}
}
?>
UpdateClick.java
public class UpdateClick extends AppCompatActivity implements View.OnClickListener {
EditText etCarModel;
EditText etCarType;
EditText etCapacity;
EditText etPlateNumber;
EditText etPrice;
ImageView ivImg;
Spinner spFuelType;
TextView tvCar_No;
ArrayAdapter<CharSequence> adapter;
Button btnSelectPhoto,btnUpdate;
GalleryPhoto galleryPhoto;
Bitmap bitmap;
final String TAG = this.getClass().getName();
final int GALLERY_REQUEST = 1231;
String selectedPhoto;
String e1,e2,e3,e4,e5,e6,i1,e7;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == GALLERY_REQUEST) {
Uri uri = data.getData();
galleryPhoto.setPhotoUri(uri);
String photoPath = galleryPhoto.getPath();
selectedPhoto = photoPath;
try {
bitmap = com.kosalgeek.android.photoutil.ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
ivImg.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "Something went wrong while opening gallery", Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_click);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
btnUpdate = (Button) findViewById(R.id.btnUpdate);
btnUpdate.setOnClickListener(this);
galleryPhoto = new GalleryPhoto(getApplicationContext());
spFuelType = (Spinner) findViewById(R.id.spFuelType);
adapter = ArrayAdapter.createFromResource(this, R.array.fuel_types,android.R.layout.simple_dropdown_item_1line);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spFuelType.setAdapter(adapter);
spFuelType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ImageLoader.getInstance().init(UILConfig.config(UpdateClick.this));
etCarModel = (EditText) findViewById(R.id.etCarModel);
etCarType = (EditText) findViewById(R.id.etCarType);
etCapacity = (EditText) findViewById(R.id.etCapacity);
etPlateNumber = (EditText) findViewById(R.id.etPlateNumber);
etPrice = (EditText) findViewById(R.id.etPrice);
tvCar_No = (TextView) findViewById(R.id.tvCar_No);
ivImg = (ImageView) findViewById(R.id.ivImg);
btnSelectPhoto = (Button) findViewById(R.id.btnSelectPhoto);
final Cars Cars = (Cars)getIntent().getSerializableExtra("cars");
Intent in = getIntent();
e1 = in.getStringExtra("e1");
e2 = in.getStringExtra("e2");
e3 = in.getStringExtra("e3");
e4 = in.getStringExtra("e4");
e5 = in.getStringExtra("e5");
e6 = in.getStringExtra("e6");
e7 = in.getStringExtra("e7");
i1 = in.getStringExtra("i1");
etCarModel.setText(e1);
etCarType.setText(e2);
etCapacity.setText(e3);
etPlateNumber.setText(e5);
etPrice.setText(e6);
tvCar_No.setText(e7);
ImageLoader.getInstance().displayImage(i1,ivImg);
btnSelectPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(galleryPhoto.openGalleryIntent(), GALLERY_REQUEST);
}
});
}
@Override
public void onClick(View v) {
try {
bitmap = com.kosalgeek.android.photoutil.ImageLoader.init().from(selectedPhoto).requestSize(512, 512).getBitmap();
String encodeImage = ImageBase64.encode(bitmap);
HashMap<String, String> post = new HashMap<String, String>();
post.put("image", encodeImage);
PostResponseAsyncTask taskUpload = new PostResponseAsyncTask(UpdateClick.this, post, new AsyncResponse() {
@Override
public void processFinish(String s) {
Log.d(TAG, s);
if (s.contains("upload_success")) {
Toast.makeText(getApplicationContext(), "Image Upload Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Error Uploading", Toast.LENGTH_SHORT).show();
}
}
});
taskUpload.execute("http://carkila.esy.es/upload1.php");
taskUpload.setEachExceptionsHandler(new EachExceptionsHandler() {
@Override
public void handleIOException(IOException e) {
Toast.makeText(getApplicationContext(), "Cannot Connect to Server", Toast.LENGTH_SHORT).show();
}
@Override
public void handleMalformedURLException(MalformedURLException e) {
Toast.makeText(getApplicationContext(), "URL Error", Toast.LENGTH_SHORT).show();
}
@Override
public void handleProtocolException(ProtocolException e) {
Toast.makeText(getApplicationContext(), "Protocol Error", Toast.LENGTH_SHORT).show();
}
@Override
public void handleUnsupportedEncodingException(UnsupportedEncodingException e) {
Toast.makeText(getApplicationContext(), "Encoding Error", Toast.LENGTH_SHORT).show();
}
});
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "Something went wrong while choosing photos", Toast.LENGTH_SHORT).show();
}
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 taskPost = new PostResponseAsyncTask(UpdateClick.this, postData, new AsyncResponse() {
@Override
public void processFinish(String s) {
Log.d("asdqwe", s);
if (s.contains("success")) {
Toast.makeText(UpdateClick.this, "Post Updated!", Toast.LENGTH_SHORT).show();
Intent in = new Intent(UpdateClick.this, OwnerTabs.class);
startActivity(in);
finish();
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
}
});
taskPost.execute("http://carkila.esy.es/update.php");
}
}
クエリをエコーすると、値は空になると思います。このようなすべての値を変更するCar_Model = '$ Car_Model' - > Car_Model = '"。$ Car_Model。"' –
はif条件を変更します。 if(!$ result){ エコー "失敗"; exit; } else { echo "成功"; exit; 'もし(!空($結果))に($結果> 0)であれば } –
変更' '' –