Java 在android设备上显示我的php echo
当我的数据库中已经存在用户名或电子邮件时,我想显示我的php回音Java 在android设备上显示我的php echo,java,php,android,mysql,android-studio,Java,Php,Android,Mysql,Android Studio,当我的数据库中已经存在用户名或电子邮件时,我想显示我的php回音 $sql = "SELECT * FROM user WHERE username='$username' OR email='$email'"; $check = mysqli_fetch_array(mysqli_query($con,$sql)); if(isset($check)){ echo "username or email already exist";
$sql = "SELECT * FROM user WHERE username='$username' OR email='$email'";
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if(isset($check)){
echo "username or email already exist";
}else {
$statement = mysqli_prepare($con, "INSERT INTO User (username, email, age, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "ssis", $username, $email, $age, $password);
}
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
当电子邮件或用户名已经存在时,它不会创建帐户,但不会显示我的回音并退出我的注册活动
这是我的ServerRequests.java
@Override
protected Void doInBackground(Void... params) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("username", user.username));
dataToSend.add(new BasicNameValuePair("email", user.email));
dataToSend.add(new BasicNameValuePair("password", user.password));
dataToSend.add(new BasicNameValuePair("age", user.age + ""));
HttpParams httpRequestParams = getHttpRequestParams();
HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS
+ "Register.php");
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
client.execute(post);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private HttpParams getHttpRequestParams() {
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams,
CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams,
CONNECTION_TIMEOUT);
return httpRequestParams;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
progressDialog.dismiss();
userCallBack.done(null);
}
@覆盖
受保护的Void doInBackground(Void…参数){
ArrayList dataToSend=新的ArrayList();
添加(新的BasicNameValuePair(“username”,user.username));
添加(新的BasicNameValuePair(“email”,user.email));
添加(新的BasicNameValuePair(“密码”,user.password));
添加(新的BasicNameValuePair(“age”,user.age+);
HttpParams httpRequestParams=getHttpRequestParams();
HttpClient客户端=新的默认HttpClient(httpRequestParams);
HttpPost=新的HttpPost(服务器地址
+“Register.php”);
试一试{
post.setEntity(新的UrlEncodedFormEntity(dataToSend));
客户。执行(post);
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
私有HttpParams getHttpRequestParams(){
HttpParams httpRequestParams=新的BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams,
连接超时);
HttpConnectionParams.setSoTimeout(httpRequestParams,
连接超时);
返回httpRequestParams;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
progressDialog.disclose();
userCallBack.done(null);
}
在PHP上用于打印的echo方法
如果你想向你的应用发送消息
只需将变量用作$msg而不是echo
并在应用程序中请求$msg
$sql = "SELECT * FROM user WHERE username='$username' OR email='$email'";
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if(isset($check)){
$msg = "username or email already exist";
}else {
$statement = mysqli_prepare($con, "INSERT INTO User (username, email, age, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "ssis", $username, $email, $age, $password);
$msg = "Created";
}
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
请使用PHP来处理密码安全性。如果您使用的PHP版本低于5.5,您可以使用
密码\u hash()
。是的,我如何请求它?到处检查,但总是有不同的答案