0

Androidエミュレーター3.1を使用してmysqlに挿入しようとしていますが、挿入できない問題があり、logcatでエラーが発生するので、誰かが私のコードを助けてくれます.mysqlに空のデータを挿入する面白い部分.

PHP

mysql_select_db("properties", $con);

$sql="INSERT INTO customer(C_Name, C_Surname, C_ID, C_Address, C_Email, C_CellNumber, C_UserName, C_Password)
   VALUES('$_POST[C_Name]','$_POST[C_Surname]','$_POST[C_ID]','$_POST[C_Address]','$_POST[C_Email]',
   '$_POST[C_CellNumber]','$_POST[C_UserName]','$_POST[C_Password]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
//echo "1 record added";

echo json_encode($sql);

mysql_close($con);

そして私の活動

protected String doInBackground(String... args) {

            String name = input_Name.getText().toString();
            String surname = input_Surname.getText().toString(); 
            String ID = input_ID.getText().toString();        
            String Address = input_Address.getText().toString();
            String Emial = input_Email.getText().toString();
            String CellNumber = input_CellNumber.getText().toString();
            String Username = input_UserName.getText().toString();
            String Pasword = input_Password.getText().toString();

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name",name)); 
            params.add(new BasicNameValuePair("surname",surname));
            params.add(new BasicNameValuePair("ID",ID));        
            params.add(new BasicNameValuePair("Address",Address));
            params.add(new BasicNameValuePair("Emial",Emial));
            params.add(new BasicNameValuePair("CellNumber",CellNumber));
            params.add(new BasicNameValuePair("Username",Username));
            params.add(new BasicNameValuePair("Pasword",Pasword));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);



            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product

                    Toast.makeText(RegisterUsers.this,"Customer has been Registered",Toast.LENGTH_LONG).show();        

                    // closing this screen
                   // finish();
                } else {
                    // failed to create product

                    Toast.makeText(RegisterUsers.this,"Error",Toast.LENGTH_LONG).show();   
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }

    }

エラーをグーグルで検索しようとしましたが、見つかりませんでした。このコードを試すのに約3時間かかるため、何をすべきかを知る必要があります。ログの猫のエラー

ログキャット

06-18 22:46:45.045: E/JSON Parser(1453): Error parsing data org.json.JSONException: Value INSERT INTO customer(C_Name, C_Surname, C_ID, C_Address, C_Email, C_CellNumber, C_UserName, C_Password)

06-18 22:46:45.045: E/JSON Parser(1453):    VALUES('','','','','',

06-18 22:46:45.045: E/JSON Parser(1453):    '','','') of type java.lang.String cannot be converted to JSONObject
06-18 22:46:45.065: W/dalvikvm(1453): threadid=9: thread exiting with uncaught exception (group=0x40014760)
06-18 22:46:45.095: E/AndroidRuntime(1453): FATAL EXCEPTION: AsyncTask #1
06-18 22:46:45.095: E/AndroidRuntime(1453): java.lang.RuntimeException: An error occured while executing doInBackground()
06-18 22:46:45.095: E/AndroidRuntime(1453):     at android.os.AsyncTask$3.done(AsyncTask.java:266)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.lang.Thread.run(Thread.java:1020)
06-18 22:46:45.095: E/AndroidRuntime(1453): Caused by: java.lang.NullPointerException
06-18 22:46:45.095: E/AndroidRuntime(1453):     at de.vogella.android.locationapi.simple.RegisterUsers$CreateNewCustomer.doInBackground(RegisterUsers.java:136)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at de.vogella.android.locationapi.simple.RegisterUsers$CreateNewCustomer.doInBackground(RegisterUsers.java:1)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at android.os.AsyncTask$2.call(AsyncTask.java:252)
06-18 22:46:45.095: E/AndroidRuntime(1453):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-18 22:46:45.095: E/AndroidRuntime(1453):     ... 4 more
4

1 に答える 1

1

これを変更する必要があります

params.add(new BasicNameValuePair("name",name)); 
params.add(new BasicNameValuePair("surname",surname));

そしてそれはこのようなphpと同じでなければなりません

params.add(new BasicNameValuePair("C_Name",name)); 
params.add(new BasicNameValuePair("C_Surname",surname));
于 2012-06-21T13:31:45.417 に答える