1. Are you ready for the Galaxy S20? Here is everything we know so far!

Need Help with Login App Using XML/HttpURL/PHP/SQL

Discussion in 'Android Development' started by ac4android, Jul 10, 2017.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter

    I am trying to create a login app using email and a password using HttpURL.
    I am getting an email/password error back from the PHP I've created on the remote server.

    Here is the XML that gets the email/password variables, the work well:
    Code (Text):
    1.  
    2.            <EditText
    3.                 android:id="@+id/et_email"
    4.                 android:layout_width="match_parent"
    5.                 android:layout_height="wrap_content"
    6.                 android:hint="@string/prompt_email"
    7.                 android:inputType="textEmailAddress"
    8.                 android:maxLines="1"
    9.                 android:singleLine="true" />
    10.  
    11.             <EditText
    12.                 android:id="@+id/et_password"
    13.                 android:layout_width="match_parent"
    14.                 android:layout_height="wrap_content"
    15.                 android:layout_below="@+id/email"
    16.                 android:layout_marginTop= "25dp"
    17.                 android:hint="@string/prompt_password"
    18.                 android:inputType="textPassword"
    19.                 android:maxLines="1"
    20.                 android:singleLine="true" />
    21.  
    Here is the part of the Android Java that grabs the email/login and send the pair to PHP:
    JunkInLogin.JPG

    And here is the PHP, it works, I tested it on Firefox,= & Chrome, it gives me the data if it gets the right email/password, else it tells me "Wrong email/password!". But it always return the result "Wrong email/password!" to my app.

    Code (Text):
    1.  
    2. $email = $_GET['email'];
    3. $password = $_GET['password'];
    4.  
    5. $sql = "SELECT b.User_ID, b.User_Name, x.Unit_ID FROM Users b
    6.    JOIN X_Users x ON TRIM(b.Email) = TRIM('$email') AND TRIM(b.Password) = TRIM('$password')";
    7. $result = mysqli_query($conn, $sql);
    8. if (mysqli_num_rows($result) > 0) {
    9.    $response = array();
    10.    while($row=mysqli_fetch_array($result)){
    11.    array_push($response, array("User_ID"=>$row[0], "User_Name"=>$row[1], "Farm_ID"=>$row[2]));
    12.    }
    13.    echo json_encode(array("db_response"=>$response));
    14.         echo'{"query_result":"Welcome back."}';
    15. } else {
    16.         echo'{"query_result":"Wrong email/password!"}';
    17. };
    18.  

    PS 7/10/2017:
    I forgot to add: JSON_STRING is null since PHP returns nothing. Worked myself into a rut again...
     


    #1 ac4android, Jul 10, 2017
    Last edited: Jul 10, 2017
    sweetndreemy73 likes this.

    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...