数据没有使用php在android中存储到数据库中

时间:2014-10-12 12:14:25

标签: php android

您好我的应用程序我正在设计一个名称,电子邮件,移动,消息的表单。单击提交按钮我想将所有记录保存到database.Data不存储到database.and logcat显示此错误。 任何人都可以帮助我。

AdmissionEnquiry

public class AdmissionEnquiry extends Activity 
{
     public void onCreate(Bundle savedInstanceState) 
        {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.admissionform);        
            final EditText name=(EditText) findViewById(R.id.name);
            final EditText email=(EditText) findViewById(R.id.email);
            final EditText mobile=(EditText) findViewById(R.id.mobile);
            final EditText address=(EditText) findViewById(R.id.address);
            final EditText enqdetails=(EditText) findViewById(R.id.enqdetail);

            Button submit = (Button) findViewById(R.id.submit); 

            submit.setOnClickListener(new OnClickListener() {               
                public void onClick(View v)
                {

                    if(name.getText().toString().length()==0)
                    {           
                        name.setError( "Please Enter Name" );
                    }
                    else if(email.getText().toString().length()==0)
                    {           
                        email.setError( "Please Enter Email" );
                    }               
                    else if(mobile.getText().toString().length()==0)
                    {           
                        mobile.setError( "Please Enter Mobile" );
                    }
                    else if(address.getText().toString().length()==0)
                    {           
                        address.setError( "Please Enter Address" );
                    }
                    else if(enqdetails.getText().toString().length()==0)
                    {           
                        enqdetails.setError( "Please Enter EnquiryDetails" );
                    }
                    else
                    {
                        try{

                        String queryString ="name="+ name
                                    +"&email="+email+"&mobile="+mobile+ "&address"+address+"&enqdetails"+enqdetails;
                        String data = DatabaseUtility.executeQueryPhp("Admissionform",queryString);
                        System.out.println(data);
                        Toast.makeText(
                                AdmissionEnquiry.this,
                                "Message:Records Saved Sucessfully",

                                Toast.LENGTH_SHORT).show();
                        }
                         catch (Exception e) {
                                e.printStackTrace();
                            }
                    }   
                }           
            });
        }
}

logcat的

10-12 08:03:26.823: E/Fail 1(2341): java.lang.IllegalArgumentException: Illegal character in fragment at index 128: http://10.0.2.2/android_connect/Admissionform.php?name=android.widget.EditText{b2e7b698 VFED..CL ......I. 79,20-320,55 #7f070007 app:id/name}&email=android.widget.EditText{b2e7bf78 VFED..CL ......I. 140,20-320,55 #7f070009 app:id/email}&mobile=android.widget.EditText{b2e746b0 VFED..CL ......I. 149,20-320,55 #7f07000b app:id/mobile}&addressandroid.widget.EditText{b2e13f38 VFED..CL ......I. 77,20-320,55 #7f07000d app:id/address}&enqdetailsandroid.widget.EditText{b2e780e0 VFED..CL .F....I. 135,20-320,55 #7f07000f app:id/enqdetail}
10-12 08:03:26.823: E/Fail 2(2341): java.lang.NullPointerException: lock == null

PHP

<?php require_once('db/connection.php');
$name = !empty($_POST['name']) ? $_POST['name'] : $_GET['name'];
$email = !empty($_POST['email']) ? $_POST['email'] : $_GET['email'];
$mobile = !empty($_POST['mobile']) ? $_POST['mobile'] : $_GET['mobile'];
$address = !empty($_POST['address']) ? $_POST['address'] : $_GET['address'];
$enqdetails = !empty($_POST['enqdetails']) ? $_POST['enqdetails'] : $_GET['enqdetails'];

$query = "insert into admissionform(name,email,mobile,address,enqdetails) VALUES('$name','$email','$mobile','$address','$enqdetails')";
$json_output = array();
if (!mysql_query($query )) {
  $json_output[] = mysql_errno() . ": ".mysql_error();
}else{
  $json_output[] = true;
}

print(json_encode($json_output));
mysql_close();
?>

1 个答案:

答案 0 :(得分:1)

你忘记了queryString中的=

String queryString ="name="+ name
 +"&email="+email+"&mobile="+mobile+ "&address"+address+"&enqdetails"+enqdetails;

应该是

String queryString ="name="+ name
 +"&email="+email+"&mobile="+mobile+ "&address="+address+"&enqdetails="+enqdetails;

编辑:  你应该像这样首先获得字符串

public void onClick(View v)
{
    final EditText name=(EditText) findViewById(R.id.name);
    final EditText email=(EditText) findViewById(R.id.email);
    final EditText mobile=(EditText) findViewById(R.id.mobile);
    final EditText address=(EditText) findViewById(R.id.address);
    final EditText enqdetails=(EditText) findViewById(R.id.enqdetail);

    String zname = name.getText().toString();
    String zemail = email.getText().toString();
    String zmobile = mobile.getText().toString();
    String zaddress = address.getText().toString();
    String zenqdetails = enqdetails.getText().toString();


    ...


    String queryString ="name="+ zname+"&email="+zemail
        +"&mobile="+zmobile+ "&address"+zaddress+"&enqdetails"+zenqdetails;
    String data = DatabaseUtility.executeQueryPhp("Admissionform",queryString);

    ...

}