<?php
require_once './connection.php';

//print_r($_POST['f']['items'][0]);
if (!isset($_POST['cust_name']) == "" && !isset($_POST['mobileno']) == "") {

    $cust_name = $_POST['cust_name'];
    $response = $_POST['response'];
    $mobileno = $_POST['mobileno'];
    $buy_date = $_POST['sell_date'];

    $query1 = " insert into tbl_call_history (cust_name,cust_response,mobile_no,call_date) "
            . " values ('$cust_name','$response','$mobileno','$buy_date')";
    echo 'query ' . $query1;
    try {
        if ($con) {
            if (mysqli_query($con, $query1)) {

                $query = 'SELECT * FROM tbl_call_history ORDER BY id desc';
                mysqli_set_charset($con, 'utf8');
                $result = mysqli_query($con, $query);
                if (mysqli_num_rows($result) > 0) {
                    $i = 1;
                    while ($row = mysqli_fetch_assoc($result)) {
                        ?>
                        <tr>
                            <td scope="row"><?php echo $i; ?></td>
                            <td><?php echo $row["cust_name"]; ?></td>
                            <td><?php echo $row["mobile_no"]; ?></td>
                            <td><?php echo $row["cust_response"]; ?></td>
                            <td><?php
                                $orgDate = $row["call_date"];
//                                                            $newDate = date("d-m-Y H:i:s", strtotime($orgDate));
                                $newDate = date("d-m-Y", strtotime($orgDate));
                                echo $newDate;
//                                                            echo $row["sell_date"]; 
                                ?>
                            </td>
                        <!--                                                        <td>
                                <a href="JavaScript:Void(0);" class="btn_edit" tabindex="8" id="<?php // echo $row["id"];         ?>"><i class="fa fa-edit"> View</i></a>
                                <a href="JavaScript:Void(0);" data-toggle="modal" data-target="#exampleModal" class="btn_delete ml-4" tabindex="9" id="<?php echo $row["id"]; ?>"><i class="fa fa-trash"> Delete</i></a>
                            </td>-->
                        </tr>
                        <?php
                        $i = $i + 1;
                    }
                } else {
                    ?>
                    <tr>
                        <td>0 results</td>
                    </tr>
                    <?php
                }

//                
            } else {
                echo "Error:01";
            }
        } else {
            echo "Error:02";
        }
    } catch (Exception $ex) {
        echo "Error:03" . $ex;
    }
}
?>
