This is a migrated thread and some comments may be shown as answers.

Undefined Index Error

1 Answer 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Benedict
Top achievements
Rank 1
Benedict asked on 24 Jul 2013, 09:32 PM
i always get this undefined index error whenever i try to insert, update or delete from a grid....using php via json...please can someone help out. and how do i name my form element in the grid? thanks 
code below:

if ($verb == "PUT") {

    // DISCLAIMER: It is better to use PHP prepared statements to communicate with the database.
    //             this provides better protection against SQL injection.
    //             [http://php.net/manual/en/pdo.prepared-statements.php][4]

    // get the parameters from the get. escape them to protect against sql injection.

    $employeeId = mysql_real_escape_string($_POST["EmpId"]);
    $firstName = mysql_real_escape_string($_POST["Fname"]);

    $rs = mysql_query("INSERT INTO users (EmpId,Fname) VALUES ('" .$employeeId. "','" .$firstName ."')");

    if ($rs) {
        echo json_encode($rs);
    }
    else {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Insert Failed";
    }
}


  <script>
                $(document).ready(function () {
                      dataSource = new kendo.data.DataSource({
                            transport: {
                                read:  {
                                    url: "data/users.php",
                                    dataType: "json",
                                    type:"GET"
                                },
                                update: {
                                    url: "data/users.php",
                                    dataType: "json",
                                    type:"POST"
                                },
                                create: {
                                    url: "data/users.php",
                                    dataType: "json",
                                    type:"PUT"
                                },
                                  destroy: {
                                    url: "data/users.php",
                                    dataType: "json",
                                    type: "DELETE"
                                }


                            },
                             error: function(e) {
                                alert(e.responseText);
                            },
                            schema: {
                            data:"data",
                            total:"total",
                            model: {

                                fields:{ Fname: { validation: { required: true} }
                                       }
                            }

                         },
                         pageSize: 10
                        });

                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        height: 430,
                        pageable: true,
                        toolbar: ["create"],
                        columns: [{field: 'EmpId', title: 'EmployeeID'},
                                 {field: 'Fname', title: 'FirstName'},
                                 { command: ["edit", "destroy"], title: "&nbsp;", width: "160px" }],
                                editable:"popup"
            });
                });
            </script>

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 26 Jul 2013, 02:00 PM
Hello Benedict,

We are not sure what exactly is causing this. Did you check the net for similar problem related to PHP ?

http://stackoverflow.com/questions/10613570/undefined-index-error-php

If possible provide a sample page that we can run to reproduce the problem.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Benedict
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or