php中未定义的变量名称错误

时间:2017-03-21 09:37:53

标签: java php android database server

在用户名,电子邮件,密码中,以下代码中出现了未定义的变量名称错误,即使它们已在表格中精确定义。

<?php
    $con = mysqli_connect("localhost", "user", "password", "dbname");

    $username = $_POST["username"];
    $email=$_POST["email"];
    $password = $_POST["password"];

    $statement = mysqli_prepare($con, "INSERT INTO `user` (`username`, `email`, `password`) VALUES (?, ?, ?)");
    mysqli_stmt_bind_param($statement, "sss", $username, $email, $password);
    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;

    echo json_encode($response);
?>

这是处理注册的活动

public class RegisterActivity extends Activity{
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        final EditText username = (EditText) findViewById(R.id.uname);
        final EditText emailid = (EditText) findViewById(R.id.eid);
        final EditText password = (EditText) findViewById(R.id.pword);
        final EditText cpword = (EditText) findViewById(R.id.cp);
        final Button regbtn = (Button) findViewById(R.id.register);
        //final String pword = password.getText().toString();
        //final String conpword = cpword.getText().toString();

        //if(pword.equals(conpword))
            regbtn.setOnClickListener(new View.OnClickListener(){
                                          public void onClick(View v){
                                          final String uname=username.getText().toString();
                                          final String mailId=emailid.getText().toString();
                                          final String pword = password.getText().toString();


                                              Response.Listener<String> resListener=new Response.Listener<String>(){

                                              @Override
                                              public void onResponse(String response) {
                                                  try {
                                                      JSONObject jsonResponse = new JSONObject(response);

                                                      Boolean success = jsonResponse.getBoolean("success");

                                                      if(success){
                                                          Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                                                          RegisterActivity.this.startActivity(intent);
                                                      }
                                                      else{
                                                          AlertDialog.Builder alertDialog = new AlertDialog.Builder(RegisterActivity.this);
                                                          alertDialog.setMessage("Registration failed")
                                                                  .setNegativeButton("Retry",null)
                                                                  .create()
                                                                  .show();
                                                      }


                                                  } catch (JSONException e) {
                                                      e.printStackTrace();
                                                  }
                                              }
                                          };

                                          RegisterRequest registerRequest = new RegisterRequest(uname,mailId,pword,resListener);
                                          RequestQueue registerQueue = Volley.newRequestQueue(RegisterActivity.this);
                                          registerQueue.add(registerRequest);

                                      }

        }

        );
}

变量的值在这里正确传递。我无法找到错误发生的位置,请帮忙。

1 个答案:

答案 0 :(得分:0)

首先,如果变量的值被正确传递,并且你请求的是&#34; POST&#34;,那么错误可能就是你json。