简体   繁体   中英

Undefined variable in php script

Seriously , I have no idea what's wrong with my php script. I'm want to update data from android to MySQL through php script. All the column value can be updated except timein . I can't figure out what's wrong in my code.

在此处输入图片说明

updateDetails.php

<?php

    if($_SERVER['REQUEST_METHOD']=='POST'){
        //Getting values 
  $id =$_POST['id'];
  $project =$_POST['project'];
  $description =$_POST['description'];
  $progress =$_POST['percentage'];
  $timeIn =$_POST['timein'];
  $timeOut = $_POST['timeout']; 

   require_once('dbConnect.php');

 $sql = "UPDATE work_details SET  project = '$project', work_description = '$description', percentage = '$progress', timeIn = '$timein' , timeOut ='$timeOut' WHERE id = $id;";

  //Updating database table 
 if(mysqli_query($con,$sql)){
 echo ' Updated Successfully';
 }else{
 echo 'Could Not Update. Try Again';
 }
 //closing connection 
 mysqli_close($con);
    }

 ?>

UpdateDetails function

public void Update( final String project, final String description, final int progress, final String timeIn, final String timeOut)
{
    class UpdateInfo extends AsyncTask<Void,Void,String>{
        ProgressDialog loading;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(Edit_Details.this,"Updating...","Wait...",false,false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            Toast.makeText(Edit_Details.this,s,Toast.LENGTH_LONG).show();
        }

        @Override
        protected String doInBackground(Void... params) {
            HashMap<String,String> hashMap = new HashMap<>();
            hashMap.put(Config.KEY_ID,ID);
            hashMap.put(Config.KEY_PROJECT,project);
            hashMap.put(Config.KEY_DESCRIPTION,description);
            hashMap.put(Config.KEY_PROGRESS,String.valueOf(progress));
            hashMap.put(Config.KEY_TIME_IN,timeIn);
            hashMap.put(Config.KEY_TIME_OUT,timeOut);
            RequestHandler rh = new RequestHandler();
            String s = rh.sendPostRequest(Config.URL_UPDATEDETAILS,hashMap);

            return s;
        }
    }

    UpdateInfo ue = new UpdateInfo();
    ue.execute();
}

Config

  public static final String KEY_TIME_IN="timein";

Your SQL statements has

"... timeIn = '$timein' ..."

But you declare the variable before that as

$timeIn =$_POST['timein']; 

Make sure you fix your upper/lower case so that the variables match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM