php - php 中 undefined index

标签 php android mysql

不知道我在这里错过了什么。当插入 workForce 数据时,我会出现此错误。当我检查MySQL时,所有数据都被插入,只有twf为0。

enter image description here

   public void addWorkForce(final String subcontractors, final String noPeople, final String noHours, final long id)
    {
        class AddWorkForce extends AsyncTask<String, Void, String> {
            ProgressDialog loading;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(WorkDetailsTable.this, "Please Wait",null, true, true);
            }

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

            @Override
            protected String doInBackground(String... params) {

                HashMap<String, String> data = new HashMap<String,String>();
                data.put(Config.KEY_SUBCONTRACTORS,subcontractors);
                data.put(Config.KEY_NUMBERPERSONS,noPeople);
                data.put(Config.KEY_NUMBERHOURS,noHours);
                data.put(Config.KEY_TWF,String.valueOf(id));
                RequestHandler rh=new RequestHandler();
                String result = rh.sendPostRequest(Config.ADD_WORKFORCE,data);
                return  result;
            }
        }

        AddWorkForce ru = new AddWorkForce();
        ru.execute(subcontractors,noPeople,noHours);
    }

addWorkForce.php

<?php 
    if($_SERVER['REQUEST_METHOD']=='POST'){

        //Getting values
        $subcontractors = $_POST['subcontractors'];
        $noPeople = $_POST['noPeople'];
        $noHours = $_POST['noHours'];
        $twf = $_POST['id'];


        //Creating an sql query
        $sql = "INSERT INTO work_force(subcontractors, number_of_person, number_of_hours, twf) VALUES ('$subcontractors','$noPeople','$noHours','$twf')";

        //Importing our db connection script
        require_once('dbConnect.php');

        //Executing query to database
        if(mysqli_query($con,$sql)){
            echo 'Work Force Added Successfully';
        }else{
            echo 'Could Not Add Work Force';
        }

        //Closing the database 
        mysqli_close($con);
    }
?>

最佳答案

检查该常量的名称:

Config.KEY_TWF

关于php - php 中 undefined index ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574405/

相关文章:

php - 它是什么?用户 'fonok@' localhost' 的访问被拒绝(使用密码 : YES)

android - 使用来自两个数据库表的数据填充 RecyclerView Item

php - 克服 PHP 中的针状大海捞针困惑

php - 我的 SQL 查询在获取数据时使用异常

php - jquery打字效果

android - WebView 在从 ICS 的下一个屏幕导航回 Webview 时显示透明颜色 (Android 4)

android - 带有来自 URL 的图像的 Imageview

php - 如何根据下拉选择更改div中的内容

php - 插入mysql不完整值字段

php - jQuery .load 怎么会失败?