Php 我不能发布数据&;使用json在localhost服务器中创建映像

Php 我不能发布数据&;使用json在localhost服务器中创建映像,php,android,mysql,json,multipartentity,Php,Android,Mysql,Json,Multipartentity,我正在使用此代码并添加了完整代码。我找不到错误所在。我想在服务器中发布我的数据和图像 } ?> 我的日志错误 10-13 20:13:12.373:W/IIInputConnectionWrapper(26253):在非活动输入连接上显示状态图标 10-13 20:13:28.292:D/dalvikvm(26253):GC_并发释放215K,5%释放7050K/7367K,暂停302ms+30ms 10-13 20:13:33.713:D/发送图片(26253):客人姓名为 10-13 20:

我正在使用此代码并添加了完整代码。我找不到错误所在。我想在服务器中发布我的数据和图像

} ?>

我的日志错误 10-13 20:13:12.373:W/IIInputConnectionWrapper(26253):在非活动输入连接上显示状态图标 10-13 20:13:28.292:D/dalvikvm(26253):GC_并发释放215K,5%释放7050K/7367K,暂停302ms+30ms 10-13 20:13:33.713:D/发送图片(26253):客人姓名为 10-13 20:13:33.713:D/发送图片(26253):客人代码为 10-13 20:13:34.976:D/Response(26253):{“成功”:0,“消息”:“缺少必需字段”}


之所以出现此错误,是因为检查php文件中post函数的“
if
”函数返回了
false
,您应该检查java代码,因为某些字段缺少描述

您的PHP脚本需要名为
name
price
description
的字段,但您似乎没有发送
description
字段。@MikeW现在我添加了description.。但我得到了相同的输出。您有解决方案吗@卡提克
public class MainActivity extends Activity {
String name, price;
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
String profilepic;
ProgressDialog pDialog;
private static int RESULT_LOAD_IMAGE = 1;
FileBody cbFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EditText name1 = (EditText) findViewById(R.id.editText1);
    EditText pwd = (EditText) findViewById(R.id.editText2);
    Button img = (Button) findViewById(R.id.button1);
    Button signup = (Button) findViewById(R.id.button2);
    name = name1.getText().toString();
    price = pwd.getText().toString();
    img.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_IMAGE);

        }
    });
    signup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new PostPicture().execute();

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
            && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        ImageView imageView = (ImageView) findViewById(R.id.imageView1);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

    }
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            Toast.makeText(getApplicationContext(), "" + selectedImagePath,
                    1000).show();
            // System.out.println("Image Path : " + selectedImagePath);

        }
    }

}

private String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

class PostPicture extends AsyncTask<String, String, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Uploading Picture");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();

    }

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        // Check for success tag

        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(
                "http://192.168.1.50/android_connect/create_product.php");

        try {

            MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            File file = new File(
                    "/mnt/sdcard/stock-vector-a-golden-soccer-ball-122478970.jpg");
            cbFile = new FileBody(file, "image/jpeg");
            StringBody sb1 = new StringBody("some text goes here");
            StringBody sb2 = new StringBody("some text goes here too");
            Log.d("sending picture", "guest name is " + name);
            Log.d("Sending picture", "guest code is " + price);
            // entity.addPart("name",tjh);
            entity.addPart("name", sb1);
            entity.addPart("price", sb2);
            // entity.addPart("description", cbFile);
            post.setEntity(entity);

            HttpResponse response1 = client.execute(post);
            HttpEntity resEntity = response1.getEntity();
            String Response = EntityUtils.toString(resEntity);
            Log.d("Response", Response);

        } catch (IOException e) {
            Log.e("asdf", e.getMessage(), e);

        }
        return null;

    }

    protected void onPostExecute(String file_url) {
        // dismiss the dialog once product deleted
        pDialog.dismiss();
        if (file_url != null) {
            Toast.makeText(MainActivity.this, file_url, Toast.LENGTH_LONG)
                    .show();
        }

    }

}
$response = array();

// check for required fields
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {

$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// mysql inserting a new row
$result = mysql_query("INSERT INTO products(name, price, description) VALUES('$name', '$price', '$description')");

// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";

    // echoing JSON response
    echo json_encode($response);
 } else {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";

    // echoing JSON response
    echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);