我面临一个奇怪的问题.我正在尝试从中删除所选项目mysql database
.虽然查询的所有内容都是正确的,但我测试了查询并且它可以工作,但它不会从数据库中删除项目.
代码:
private class DeleteData extends AsyncTask> { @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(CartActivity.this); progressDialog.setMessage(getString(R.string.get_stocks)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.show(); } @Override protected List doInBackground(String... params) { nameValuePairs = new ArrayList<>(); cartItems = new ArrayList<>(); try { url = new URL(params[0]); httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setReadTimeout(10000); httpURLConnection.setConnectTimeout(15000); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); deleteDataInDB(); outputStream = httpURLConnection.getOutputStream(); bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream)); bufferedWriter.write(StringGenerator.queryResults(nameValuePairs)); bufferedWriter.flush(); bufferedWriter.close(); outputStream.close(); httpURLConnection.connect(); inputStream = new BufferedInputStream(httpURLConnection.getInputStream()); jsonResult = StringGenerator.inputStreamToString(inputStream, CartActivity.this); Log.e("Response: ", jsonResult.toString()); } catch (IOException e) { e.printStackTrace(); } return cartItems; } @Override protected void onPostExecute(List cartLists) { super.onPostExecute(cartLists); progressDialog.dismiss(); } }
设置方法:
private void deleteDataInDB(){ nameValuePairs.add(new BasicNameValuePair(AppConstant.PRODUCT_NAME_VALUE_PAIR, nameAdapter)); Log.e("Name Adapter Value: ", nameAdapter); nameValuePairs.add(new BasicNameValuePair(AppConstant.COMPANY_INTENT_ID, magazi_id)); Log.e("Magazi id: ", magazi_id); nameValuePairs.add(new BasicNameValuePair(AppConstant.PRODUCT_WAITER_ID_VALUE_PAIR, servitoros_id)); Log.e("Servitoros id: ", servitoros_id); nameValuePairs.add(new BasicNameValuePair(AppConstant.PRODUCT_TABLE_ID_VALUE_PAIR, table)); Log.e("Table: ", table); }
我执行任务的地方:
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()){ case R.id.deleteCartItemModification:{ for (int position = 0; position响应:
12-17 05:37:24.043 2099-2099/com.order.app.order E/Names Added:: [BLT Sandwich, Club Sandwich] 12-17 05:37:24.045 2099-2099/com.order.app.order I/AppCompatDelegate: The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's 12-17 05:37:24.086 2099-2118/com.order.app.order W/EGL_emulation: eglSurfaceAttrib not implemented 12-17 05:37:24.086 2099-2118/com.order.app.order W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0883cc0, error=EGL_SUCCESS 12-17 05:37:26.390 2099-2118/com.order.app.order D/OpenGLRenderer: endAllStagingAnimators on 0xa1ce1b00 (RippleDrawable) with handle 0xa18d8700 12-17 05:37:26.417 2099-2123/com.order.app.order E/Response:: DELETE FROM cart WHERE product_name='Club Sandwich' AND magazi_id='53' AND servitoros_id='724' AND trapezi='3' 12-17 05:37:26.430 2099-2118/com.order.app.order W/EGL_emulation: eglSurfaceAttrib not implemented 12-17 05:37:26.430 2099-2118/com.order.app.order W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0883cc0, error=EGL_SUCCESS 12-17 05:37:26.445 2099-2123/com.order.app.order E/Response:: DELETE FROM cart WHERE product_name='Club Sandwich' AND magazi_id='53' AND servitoros_id='724' AND trapezi='3'而名称添加是:
[BLT Sandwich, Club Sandwich]
响应是最后一个对象的两倍:
E/Response:: DELETE FROM cart WHERE product_name='Club Sandwich' AND magazi_id='53' AND servitoros_id='724' AND trapezi='3' E/Response:: DELETE FROM cart WHERE product_name='Club Sandwich' AND magazi_id='53' AND servitoros_id='724' AND trapezi='3'deleteDataWebService:
private void deleteDataWebService(){ DeleteData deleteData = new DeleteData(); deleteData.execute(AppConstant.DELETE_URL); }PHP文件:
setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8 "); $handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $handler->exec("SET CHARACTER SET 'utf8'"); } catch (Exception $e) { echo $e->getMessage(); die(); } $productName = $_POST['productName']; $magazi = $_POST['magazi_id']; $servitoros = $_POST['servitoros_id']; $trapezi = $_POST['trapezi']; $handler->query("DELETE FROM cart WHERE product_name='$productName' AND magazi_id='$magazi' AND servitoros_id='$servitoros' AND trapezi='$trapezi'"); die("Deleted"); ?>并且只删除最后一项.有任何想法吗?