回应:不对。 [使用HTTP POST通过Android应用程序用户注册不灵] [英] Response:wrong. [User registration via android app using http post not working]

查看:262
本文介绍了回应:不对。 [使用HTTP POST通过Android应用程序用户注册不灵]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是能够成功地使登录工作。现在,我坚持了注册。反应是错误的。

I was able to successfully make login work. Now, I am stuck up with registration. Response is wrong.

public class Register extends Activity implements OnClickListener{

    private String mTitle = "Write.My.Action";

    private static final String LOGTAG = "tag";
    public EditText fullname, email, password;
    private Button register; 
    private ProgressDialog mDialog; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        getActionBar().setTitle(mTitle);

        fullname = (EditText) findViewById(R.id.fullname);
        email = (EditText) findViewById(R.id.editText2);
        password = (EditText) findViewById(R.id.editText1);

        register = (Button) findViewById(R.id.button1);

        register.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            mDialog = new ProgressDialog(Register.this);
            mDialog.setMessage("Attempting to Register...");
            mDialog.setIndeterminate(false);
            mDialog.setCancelable(false);
            mDialog.show();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    register();

                }
            }).start();
        }

    }

     void register() {
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("myurl");

            System.out.println("httpPost is: " + httpPost);

            String fullname_input = fullname.getText().toString().trim();
            String email_input = email.getText().toString().trim();
            String password_input = password.getText().toString().trim();

            //adding data into list view so we can make post over the server

            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
            nameValuePair.add(new BasicNameValuePair("fullname",  fullname_input));
            nameValuePair.add(new BasicNameValuePair("email",  email_input));
            nameValuePair.add(new BasicNameValuePair("password",  password_input));

            System.out.println("namevaluepair is: " + nameValuePair);
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));

            //execute http post resquest

            HttpResponse httpResponse = httpClient.execute(httpPost);



            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpClient.execute(httpPost, responseHandler);

            System.out.println("Response is: " + response);

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mDialog.dismiss();

                }
            });
            if(response.equalsIgnoreCase("Signed Up")){
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        startActivity(new Intent(Register.this, Registration_Success.class));

                    }
                });
            }else {
                showAlert();
            }

        } catch (Exception e) {
            mDialog.dismiss();
            Log.i(LOGTAG, "Exception found"+ e.getMessage());
        }

    }
     public void showAlert(){
         Register.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
                builder.setTitle("Registration Error");
                builder.setMessage("Please, try registration again!")
                        .setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub

                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();

            }
        });
     }
}

请注意:每一个活动都登记在清单,INTERNET权限还包​​括

php文件:

include "dbconnection.php";

$fullname = $_POST['fullname'];
$email = $_POST['email'];
$password = $_POST['password'];

$insert_data = "INSERT INTO register
    Values ('', '$fullname', '$email', '$password')";

$insert_result = mysql_query($insert_data);
//echo "Signed Up";

if($insert_result){
echo "Signed Up";
}
else{
 echo "wrong!";
} 

我不明白为什么它口口声声说的回应是:错。厌倦了几乎一天花费..我在这里寻求帮助。
原谅我,如果我的问题显得幼稚。
先谢谢你。

I don't understand why it keeps on saying Response is : Wrong. Tired of spending almost a day .. I am here seeking help. Excuse me if my questions seems naive. Thank you in advance.

推荐答案

例如@ 安德鲁牛逼的建议,我张贴我的解决方案。
mysql_error()帮我调试的问题。 mysql_error()显示在logcat中的登记表中没有找到..但表名是寄存器。我在年底失踪S。

Like @Andrew T suggested , I am posting my solution. The mysql_error()helped me debug the issue. mysql_error() displayed in the Logcat that "register table is not found" .. but the table name is registers. I was missing "s" at the end.

    $fullname = $_POST['fullname'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    $insert_data = "INSERT INTO registers(id, fullname, email, password)
        Values ('','$fullname', '$email', '$password')";

    $insert_result = mysql_query($insert_data) or die(mysql_error());
    //echo "Signed Up";

    if($insert_result){
    echo "Signed Up";
    }
    else{
     echo "wrong!";
    } 

一切的工作之后完美。再次感谢大家的时间和解决方案。每个人的建议是伟大的,但我不能接受这一点的答案..对不起:(

Everything worked perfect after that. Again, thank you all for your time and solutions. Everyone's suggestions are great, but I can not accept any answer at this point.. sorry:(

这篇关于回应:不对。 [使用HTTP POST通过Android应用程序用户注册不灵]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆