我正在为我的应用程序执行注册登录活动,当我注册所有信息时,除了电子邮件之外,所有信息都将转到我的数据库。即使我输入了正常的电子邮件地址,我在数据库中得到一个“0”值。
我检查了我的代码和我的php文件中的所有内容,但找不到问题。
public class createAccountActivity extends AppCompatActivity implements View.OnClickListener {
EditText etUsername,etEmail, etAge, etPassword;
Button register;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.createaccount);
etUsername = (EditText) findViewById(R.id.create_username);
etEmail = (EditText) findViewById(R.id.create_email);
etAge = (EditText) findViewById(R.id.create_age);
etPassword = (EditText) findViewById(R.id.create_password);
etConfirmPassword = (EditText) findViewById(R.id.confirm_password);
}
@Override
public void onClick (View v) {
switch (v.getId()){
case R.id.register:
String username = etUsername.getText().toString();
String email = etEmail.getText().toString();
int age = Integer.parseInt(etAge.getText().toString());
String password = etPassword.getText().toString();
User user = new User(username, email, age, password);
registerUser(user);
break;
}
}
private void registerUser(User user) {
ServerRequests serverRequest = new ServerRequests(this);
serverRequest.storeUserDataInBackground(user, new GetUserCallback() {
@Override
public void done(User returnedUser) {
Intent loginIntent = new Intent(createAccountActivity.this, Login.class);
startActivity(loginIntent);
}
});
}
}
在我的UserLocalStore.java中,我得到了
public void storeUserData(User user) {
SharedPreferences.Editor userLocalDatabaseEditor = userLocalDatabase.edit();
userLocalDatabaseEditor.putString("username", user.username);
userLocalDatabaseEditor.putString("email", user.email);
userLocalDatabaseEditor.putString("password", user.password);
userLocalDatabaseEditor.putInt("age", user.age);
userLocalDatabaseEditor.commit();
}
我的班级用户
public class User {
String username, email, password;
int age;
public User(String username,String email , int age, String password) {
this.username = username;
this.age = age;
this.email = email;
this.password = password;
}
public User(String username, String password) {
this(username,"", -1, password);
}
}
我的ServerRequests.class
if (jObject.length() != 0){
Log.v("happened", "2");
String username = jObject.getString("username");
int age = jObject.getInt("age");
String email = jObject.getString("email");
returnedUser = new User(username, user.username, age, user.password);
}
} catch (Exception e) {
e.printStackTrace();
}
return returnedUser;
}
答案 0 :(得分:0)
似乎ServerRequests.class中的returnedUser将user.username放在电子邮件应该放在的位置,因为你已将其声明为
public User(String username,String email , int age, String password)
它说
returnedUser = new User(username, user.username, age, user.password);
在另一个档案中。
答案 1 :(得分:0)
答案很简单,在我的register.php中它写的是“siss”而不是“ssis”所以它被视为一个int。
mysqli_stmt_bind_param($statement, "siss", $username, $email, $age, $password);
正确的一个:
mysqli_stmt_bind_param($statement, "ssis", $username, $email, $age, $password);
对不起,我应该提供它(php文件),难怪我没有得到解决方案。