php - 为什么用户名在数据库中注册为空?

标签 php android mysql android-studio

我目前正在开发一个 Android 应用程序,并完成了 Android 的注册和登录表单。

唯一的问题是用户名始终声明为 0。

希望你能理解我,也能帮助我!

MySql output

php代码: http://textuploader.com/djedy

[编辑]

android-studio代码:

public class RegisterActivity extends AppCompatActivity {

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

    final EditText etAge = (EditText) findViewById(R.id.etAge);
    final EditText etName = (EditText) findViewById(R.id.etName);
    final EditText etUsername = (EditText) findViewById(R.id.etUsername);
    final EditText etPassword = (EditText) findViewById(R.id.etPassword);

    final Button bRegister = (Button) findViewById(R.id.bRegister);

    bRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String name = etName.getText().toString();
            final String username = etUsername.getText().toString();
            final int age = Integer.parseInt(etAge.getText().toString());
            final String password = etPassword.getText().toString();

            Response.Listener<String> responseListener = 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, LoginActivity.class);
                            RegisterActivity.this.startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                            builder.setMessage("Register Failed")
                                    .setNegativeButton("Retry", null)
                                    .create()
                                    .show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };

            RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
            RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
            queue.add(registerRequest);
        }
    });
}

}

最佳答案

您正在将用户名绑定(bind)为整数值。

mysqli_stmt_bind_param($statement, "siss", $name, $username, $age, $password);

我的假设是您想将 $age 绑定(bind)为整数值?

尝试将上面的内容更改为:

mysqli_stmt_bind_param($statement, "ssis", $name, $username, $age, $password);

希望这有帮助!

<小时/>

编辑:希望您只是在测试并将实现这一点,但您需要对您的密码进行哈希处理!

请查看此内容:http://php.net/manual/en/function.crypt.php

并开始使用 password_hash()password_verify() 函数作为登录/注册脚本的一部分。

关于php - 为什么用户名在数据库中注册为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46521511/

相关文章:

php - 将注册信息插入Mysql数据库时出现问题

php - Moodle 中不存在表 'mdl_sessions'

mysql - Group_concat 具有复杂查询或子查询输出?

mysql - SUM 子查询?

php无法接收Android使用HttpURLConnection发送的数据

php - 单例 PDO 模型 - 层次结构

android - 有什么方法可以知道哪个xml文件没有在我们的项目中使用

java - 从 ListView 单击获取自定义对象

android - 无法理解 'Partially visible' 的含义

mysql - SQL 中的 IF/CASE 语句