2016-01-28 13 views
-1

我想表明我的PHP回声时的用户名或电子邮件在我的数据库已经存在显示我的PHP回声的Android设备

$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); 
    } 
+1

请使用PHP的[内置函数](http://jayblanchard.net/proper_password_hashing_with_PHP.html)来处理密码安全性。如果您使用的PHP版本低于5.5,则可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。 –

回答

0

回波法对PHP用于打印 如果你想将消息发送到您的应用程序 只需使用变量$味精,而不是回声 并要求$味精在您的应用程序中

$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); 
+0

是的,我该如何要求?到处检查,但总是不同的答案 – Bifista