Php 从Android向MySQL数据库写入数据显示错误

Php 从Android向MySQL数据库写入数据显示错误,php,android,mysql,performance,apache,Php,Android,Mysql,Performance,Apache,嗨,我正在做一个大学项目,每次用户填写信息并点击注册按钮时,在数据库中创建一个新记录。im使用apache服务器、php和mysql数据库以及java。我将php文件保存在apache文件夹中,并使用localhost调用这些文件。 我还使用jason类来查看数据 我的问题是: 每次我填写信息并点击注册按钮时,应用程序都无法在数据库中创建记录,我到处都在搜索解决方案,但没有找到任何解决方案,我希望有人能帮助我。 提前谢谢 这是注册页面的代码: package tigris.codes.Regis

嗨,我正在做一个大学项目,每次用户填写信息并点击注册按钮时,在数据库中创建一个新记录。im使用apache服务器、php和mysql数据库以及java。我将php文件保存在apache文件夹中,并使用localhost调用这些文件。 我还使用jason类来查看数据

我的问题是: 每次我填写信息并点击注册按钮时,应用程序都无法在数据库中创建记录,我到处都在搜索解决方案,但没有找到任何解决方案,我希望有人能帮助我。 提前谢谢

这是注册页面的代码:

package tigris.codes.Registration.system;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Registration extends Activity {
    //Declaring Variables
    EditText StudentName,StudentEmail,StudentPassword,StudentMobNumber,StudentNumber;
    Button RegisterButton;
    JSONParser jsonParser = new JSONParser();
    private ProgressDialog pDialog;

    // url to create new product
    private static String url_create_product = "http://localhost/android_connect/create_product.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);

        //Linking Objects
        StudentName         =   (EditText) findViewById(R.id.RegNameEditText);
        StudentEmail        =   (EditText) findViewById(R.id.RegEmailEditText);
        StudentPassword     =   (EditText) findViewById(R.id.RegPasswordEditText);
        StudentMobNumber    =   (EditText) findViewById(R.id.RegPhoneEditText);
        StudentNumber       =   (EditText) findViewById(R.id.RegStudentNumber);
        RegisterButton      =   (Button)   findViewById(R.id.registerUserButton);


        //Setting Button Event
        RegisterButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                // creating new product in background thread
                new CreateNewProduct().execute();
            }
        }); 
    }//End of onCreate method




    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Registration.this);
            pDialog.setMessage("Creating Product..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            String name      = StudentName.getText().toString();
            String password  = StudentPassword.getText().toString();
            String email     = StudentEmail.getText().toString();
            String phone     = StudentMobNumber.getText().toString();
            String snumber   = StudentNumber.getText().toString();

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("password", password));
            params.add(new BasicNameValuePair("email", email));
            params.add(new BasicNameValuePair("phone", phone));
            params.add(new BasicNameValuePair("snumber", snumber));

            // 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
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } 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();
        }

    }



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

}//end of main class
10-24 13:44:49.141: E/Buffer Error(1520): Error converting result java.lang.NullPointerException: lock == null
10-24 13:44:49.161: E/JSON Parser(1520): Error parsing data org.json.JSONException: End of input at character 0 of 
10-24 13:44:49.361: E/AndroidRuntime(1520): FATAL EXCEPTION: AsyncTask #1
10-24 13:44:49.361: E/AndroidRuntime(1520): java.lang.RuntimeException: An error occured while executing doInBackground()
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.lang.Thread.run(Thread.java:856)
10-24 13:44:49.361: E/AndroidRuntime(1520): Caused by: java.lang.NullPointerException
10-24 13:44:49.361: E/AndroidRuntime(1520):     at tigris.codes.attendance.system.Registration$CreateNewProduct.doInBackground(Registration.java:107)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at tigris.codes.attendance.system.Registration$CreateNewProduct.doInBackground(Registration.java:1)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-24 13:44:49.361: E/AndroidRuntime(1520):     ... 4 more
10-24 13:44:52.711: E/WindowManager(1520): Activity tigris.codes.attendance.system.Registration has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40cff448 V.E..... R.....ID 0,0-329,175} that was originally added here
10-24 13:44:52.711: E/WindowManager(1520): android.view.WindowLeaked: Activity tigris.codes.attendance.system.Registration has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40cff448 V.E..... R.....ID 0,0-329,175} that was originally added here
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-24 13:44:52.711: E/WindowManager(1520):  at android.app.Dialog.show(Dialog.java:281)
10-24 13:44:52.711: E/WindowManager(1520):  at tigris.codes.attendance.system.Registration$CreateNewProduct.onPreExecute(Registration.java:80)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.AsyncTask.execute(AsyncTask.java:534)
10-24 13:44:52.711: E/WindowManager(1520):  at tigris.codes.attendance.system.Registration$1.onClick(Registration.java:57)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.View.performClick(View.java:4204)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.View$PerformClick.run(View.java:17355)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Handler.handleCallback(Handler.java:725)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Looper.loop(Looper.java:137)
10-24 13:44:52.711: E/WindowManager(1520):  at android.app.ActivityThread.main(ActivityThread.java:5041)
10-24 13:44:52.711: E/WindowManager(1520):  at java.lang.reflect.Method.invokeNative(Native Method)
10-24 13:44:52.711: E/WindowManager(1520):  at java.lang.reflect.Method.invoke(Method.java:511)
10-24 13:44:52.711: E/WindowManager(1520):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-24 13:44:52.711: E/WindowManager(1520):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-24 13:44:52.711: E/WindowManager(1520):  at dalvik.system.NativeStart.main(Native Method)
package tigris.code.Registration.system;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.apache.http.message.BasicNameValuePair;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.util.Log;
导入android.view.Menu;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
公营班级注册扩展活动{
//声明变量
EditText StudentName、StudentEmail、StudentPassword、StudentMobNumber、StudentNumber;
按钮寄存器按钮;
JSONParser JSONParser=新的JSONParser();
私人对话;
//创建新产品的url
私有静态字符串url\u创建\u产品=”http://localhost/android_connect/create_product.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u注册);
//链接对象
StudentName=(EditText)findViewById(R.id.RegNameEditText);
StudentEmail=(EditText)findViewById(R.id.RegEmailEditText);
StudentPassword=(EditText)findViewById(R.id.RegPasswordEditText);
StudentMobNumber=(EditText)findViewById(R.id.RegPhoneEditText);
StudentNumber=(EditText)findViewById(R.id.RegStudentNumber);
RegisterButton=(按钮)findViewById(R.id.registerUserButton);
//设置按钮事件
RegisterButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//在后台线程中创建新产品
新建CreateNewProduct().execute();
}
}); 
}//onCreate方法的结束
/**
*创建新产品的后台异步任务
* */
类CreateNewProduct扩展了AsyncTask{
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(Registration.this);
pDialog.setMessage(“创建产品…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
/**
*创造产品
* */
受保护的字符串doInBackground(字符串…args){
String name=StudentName.getText().toString();
字符串密码=StudentPassword.getText().toString();
字符串email=StudentEmail.getText().toString();
字符串phone=StudentMobNumber.getText().toString();
String snumber=StudentNumber.getText().toString();
//建筑参数
List params=new ArrayList();
参数添加(新的BasicNameValuePair(“名称”),名称);
添加(新的BasicNameValuePair(“密码”,password));
参数添加(新的BasicNameValuePair(“电子邮件”),电子邮件);
参数添加(新的BasicNameValuePair(“电话”,电话));
添加参数(新的BasicNameValuePair(“snumber”,snumber));
//获取JSON对象
//请注意,创建产品url接受POST方法
JSONObject json=jsonParser.makeHttpRequest(url\u create\u product,
“POST”,params);
//检查cat fro响应日志
d(“创建响应”,json.toString());
//检查成功标签
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
//已成功创建产品
Intent i=新的Intent(getApplicationContext(),MainActivity.class);
星触觉(i);
//关闭此屏幕
完成();
}否则{
//未能创建产品
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
/**
*完成后台任务后,关闭“进度”对话框
* **/
受保护的void onPostExecute(字符串文件\u url){
//完成后关闭对话框
pDialog.disclose();
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.registration,menu);
返回true;
}//布尔值onCreateOptionMenu结束
}//主课结束
这些是我在日志cat中得到的错误:

package tigris.codes.Registration.system;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Registration extends Activity {
    //Declaring Variables
    EditText StudentName,StudentEmail,StudentPassword,StudentMobNumber,StudentNumber;
    Button RegisterButton;
    JSONParser jsonParser = new JSONParser();
    private ProgressDialog pDialog;

    // url to create new product
    private static String url_create_product = "http://localhost/android_connect/create_product.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);

        //Linking Objects
        StudentName         =   (EditText) findViewById(R.id.RegNameEditText);
        StudentEmail        =   (EditText) findViewById(R.id.RegEmailEditText);
        StudentPassword     =   (EditText) findViewById(R.id.RegPasswordEditText);
        StudentMobNumber    =   (EditText) findViewById(R.id.RegPhoneEditText);
        StudentNumber       =   (EditText) findViewById(R.id.RegStudentNumber);
        RegisterButton      =   (Button)   findViewById(R.id.registerUserButton);


        //Setting Button Event
        RegisterButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                // creating new product in background thread
                new CreateNewProduct().execute();
            }
        }); 
    }//End of onCreate method




    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Registration.this);
            pDialog.setMessage("Creating Product..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {
            String name      = StudentName.getText().toString();
            String password  = StudentPassword.getText().toString();
            String email     = StudentEmail.getText().toString();
            String phone     = StudentMobNumber.getText().toString();
            String snumber   = StudentNumber.getText().toString();

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("password", password));
            params.add(new BasicNameValuePair("email", email));
            params.add(new BasicNameValuePair("phone", phone));
            params.add(new BasicNameValuePair("snumber", snumber));

            // 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
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } 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();
        }

    }



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

}//end of main class
10-24 13:44:49.141: E/Buffer Error(1520): Error converting result java.lang.NullPointerException: lock == null
10-24 13:44:49.161: E/JSON Parser(1520): Error parsing data org.json.JSONException: End of input at character 0 of 
10-24 13:44:49.361: E/AndroidRuntime(1520): FATAL EXCEPTION: AsyncTask #1
10-24 13:44:49.361: E/AndroidRuntime(1520): java.lang.RuntimeException: An error occured while executing doInBackground()
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.lang.Thread.run(Thread.java:856)
10-24 13:44:49.361: E/AndroidRuntime(1520): Caused by: java.lang.NullPointerException
10-24 13:44:49.361: E/AndroidRuntime(1520):     at tigris.codes.attendance.system.Registration$CreateNewProduct.doInBackground(Registration.java:107)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at tigris.codes.attendance.system.Registration$CreateNewProduct.doInBackground(Registration.java:1)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-24 13:44:49.361: E/AndroidRuntime(1520):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-24 13:44:49.361: E/AndroidRuntime(1520):     ... 4 more
10-24 13:44:52.711: E/WindowManager(1520): Activity tigris.codes.attendance.system.Registration has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40cff448 V.E..... R.....ID 0,0-329,175} that was originally added here
10-24 13:44:52.711: E/WindowManager(1520): android.view.WindowLeaked: Activity tigris.codes.attendance.system.Registration has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40cff448 V.E..... R.....ID 0,0-329,175} that was originally added here
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-24 13:44:52.711: E/WindowManager(1520):  at android.app.Dialog.show(Dialog.java:281)
10-24 13:44:52.711: E/WindowManager(1520):  at tigris.codes.attendance.system.Registration$CreateNewProduct.onPreExecute(Registration.java:80)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.AsyncTask.execute(AsyncTask.java:534)
10-24 13:44:52.711: E/WindowManager(1520):  at tigris.codes.attendance.system.Registration$1.onClick(Registration.java:57)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.View.performClick(View.java:4204)
10-24 13:44:52.711: E/WindowManager(1520):  at android.view.View$PerformClick.run(View.java:17355)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Handler.handleCallback(Handler.java:725)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 13:44:52.711: E/WindowManager(1520):  at android.os.Looper.loop(Looper.java:137)
10-24 13:44:52.711: E/WindowManager(1520):  at android.app.ActivityThread.main(ActivityThread.java:5041)
10-24 13:44:52.711: E/WindowManager(1520):  at java.lang.reflect.Method.invokeNative(Native Method)
10-24 13:44:52.711: E/WindowManager(1520):  at java.lang.reflect.Method.invoke(Method.java:511)
10-24 13:44:52.711: E/WindowManager(1520):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-24 13:44:52.711: E/WindowManager(1520):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-24 13:44:52.711: E/WindowManager(1520):  at dalvik.system.NativeStart.main(Native Method)
10-2413:44:49.141:E/缓冲区错误(1520):转换结果java.lang.NullPointerException:lock==null时出错
10-24 13:44:49.161:E/JSON解析器(1520):解析数据org.JSON.JSONException时出错:输入结束,位于
10-2413:44:49.361:E/AndroidRuntime(1520):致命