title: How to retrieve data from a MYSQL Database and do validation in Android on Button click
body: <p>I have an Android app which is used to insert user records for each User.Each user can input data into the database only 2 times a day. If the user tries to input data the third time(click the Submit button),a new activity(in Android) will be shown with a message and the date field(TextView) should be incremented by 1 Day.I am able to add the date field by 1 day on every click. So what I have tried is to get the count of data in the MYSQL database of each user for the particular day and if the count is greater than 3, then the PHP Script will return an echo statement according to which the Async Task in Anroid will function and show the new Activity.</p>
  
  <p>My PHP Script is:</p>
  
  <pre><code>   &lt;?php
  require "conn.php";
  require "SalesLogin.php";
  
  $enquiry = $_POST["enquiry"];
  $retail = $_POST["retail"];
  $collection = $_POST["collection"];
  $booking = $_POST["booking"];
  $evaluation = $_POST["evaluation"];
  $test_drive = $_POST["test_drive"];
  $home_visit = $_POST["home_visit"];
  $user_name = $_POST["user_name"];
  $update_date = $_POST["date"];
  $absent = $_POST["absent"];
  
  
  $timezone = new DateTimeZone("Asia/Kolkata" );
  $date = new DateTime();
  $date-&gt;setTimezone($timezone );
  $time =  $date-&gt;format( 'H:i:s A' );
  
  
  $sql = "UPDATE employee_details SET
  enquiry_sum = (SELECT SUM(enquiry) +'$enquiry' FROM (SELECT * FROM employee_details WHERE date = CURDATE() AND name = '$user_name') AS x)
  WHERE date = CURDATE() AND name = '$user_name'";
  $res = $conn-&gt;query($sql);
  
  $check = "UPDATE employee_details SET enquiry_target_status = ( SELECT IF (MAX(enquiry_sum) = 52, 'ACHIEVED', 'NOT ACHIEVED') FROM (SELECT * from employee_details WHERE date = CURDATE() AND name = '$user_name') AS Y ) WHERE date = CURDATE() AND name = '$user_name'";
  $insert_status = $conn-&gt;query($check);
  
  
  $miss_count = "UPDATE employee_details SET enquiry_target_missed_by = (SELECT (50 - MAX(enquiry_sum)) FROM (SELECT * from employee_details WHERE date = CURDATE() AND name = '$user_name') AS Z ) WHERE date = CURDATE() AND name = '$user_name'";
  $insert_status = $conn-&gt;query($miss_count);
  
  
  $mysql_qry1 = "INSERT INTO employee_details(enquiry,retail, 
  collection,booking, evaluation, test_drive, home_visit, name, date,time,absent) values ('$enquiry','$retail','$collection','$booking','$evaluation','$test_drive',
  '$home_visit','$user_name','$update_date','$time','$absent');";
  
  if($conn-&gt;query($mysql_qry1) === TRUE) 
      echo "Your details has been successfully inserted.";
  
  else 
      echo "Error: " .$mysql_qry1. "&lt;br&gt;" . $conn-&gt;error;
  
  
  if($update_date != $date){
  $mysql_qry2 = "UPDATE employee_data SET last_updated_date = (DATE_ADD('$update_date', INTERVAL 1 DAY)) WHERE name = '$user_name';";
  $conn-&gt;query($mysql_qry2);
  echo "Date changed," .$mysql_qry2;
  } 
  
  
  $mysql_qry3 = "SELECT COUNT(*) from employee_details WHERE date = '$update_date' and name LIKE '$user_name';";
  $conn-&gt;query($mysql_qry3);
        if($mysl_qry3 &lt;= 2) 
                {
                     echo "You can login.";
                } 
           else 
                {
                    echo "You cannot login anymore for today.";
               }
  
  
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>My AsyncTask code is:</p>
  
  <pre><code>@Override
      protected void onPostExecute(String result) {
          try {
              if (result.contains("Welcome") &amp;&amp; result.contains("Date")) {
                  String[] str = result.split("_");
                  String name = str[1];
  
                  String[] date = result.split(":");
                  String upd_date = date[1];
                  Intent intent = new Intent(context,InsertDataActivity.class);
                  intent.putExtra("username",name);
                  intent.putExtra("date",upd_date);
                  context.startActivity(intent);
              }
              else if (result.contains("Login failed.") &amp;&amp; !(result.contains("Undefined")))
  
                  Toast.makeText(context,"Invalid Crendentials.",Toast.LENGTH_LONG).show();
  
              else if (result.contains("You cannot login anymore for today.")) {
                  Log.i("Check",result);
                  Intent intent = new Intent(context,ThankYouActivity.class);
                  context.startActivity(intent);
  
              }
  
          } catch (NullPointerException e) {
  
              Toast.makeText(context,"No Internet Connectivity found.Please connect to the internet first and then retry.",Toast.LENGTH_LONG).show();
          }
          }
  </code></pre>
  
  <p>But my code is not working properly. Can anyone please help me with this?</p>