【问题标题】:Undefined variable in php scriptphp脚本中未定义的变量
【发布时间】:2016-01-06 13:58:36
【问题描述】:

说真的,我不知道我的 php 脚本有什么问题。我想通过 php 脚本将数据从 android 更新到 MySQL。 timein之外的所有列值都可以更新。我无法弄清楚我的代码有什么问题。

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函数

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();
}

配置

  public static final String KEY_TIME_IN="timein";

【问题讨论】:

  • 你已经定义了 $timeIn 变量,但是在你的查询中使用了 $timein 变量,所以你得到了这个错误。
  • ON updatedatail.php,毕竟变量(echo $timein; exit();)
  • @GirishPatidar 谢谢……真是个愚蠢的错误……

标签: php android mysql


【解决方案1】:

你的 SQL 语句有

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

但是你在此之前声明变量为

$timeIn =$_POST['timein']; 

确保您修正了大写/小写,以便变量匹配。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-14
  • 1970-01-01
相关资源
最近更新 更多