Isset works on Local server, but it doesn't on live server

66
January 11, 2019, at 1:10 PM

I'm developing website on my local using Xampp v3.2.2, I'm running query for filtering my data, it works fine on my local but when I upload (updated my code on server) it always return 0 value. My server using native php 5.6

I've already putting !empty instead isset, but it's not working. So here's one of my filter's code:

    $this->_require_login();
    $user = $this->session->userdata('user_id');
    $cust = $this->input->post('cust_name');
    $dtstart = new DateTime($this->input->post('date_start'));
    $dtend = new DateTime($this->input->post('date_end'));
    $start_date = $dtstart->format('Y-m-d ');        
    $end_date = $dtend->format('Y-m-d ');        

    if ((isset($cust) && !empty($cust)) && (isset($start_date) && !empty($start_date)) && (isset($end_date) && !empty($end_date))){
        $this->db->select('t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
                ->from('activity as t1')
                ->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
                ->where('t1.cust_name', $cust)
                ->where('t2.user_id', $user)
                ->where('DATE(t1.date_added) >= ', $start_date)
                ->where('DATE(t1.date_modified) <= ', $end_date);
        $query = $this->db->get();
        $result = $query->result_array();                        
    if ($result) {
        $this->output->set_output(json_encode([
            'result' => 1,
            'data' => $query->result_array()
        ]));
        return false;            
    }
    $this->output->set_output(json_encode([
        'result' => 0,
        'error' => 'Could not find data.'
    ]));
    }

On my local it returns corresponding records, but on live server it returns 0.

Answer 1

You have no else statement:

<?php
if ((isset($cust) && !empty($cust)) && (isset($start_date) && !empty($start_date)) && (isset($end_date) && !empty($end_date))){
        $this->db->select('t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
                ->from('activity as t1')
                ->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
                ->where('t1.cust_name', $cust)
                ->where('t2.user_id', $user)
                ->where('DATE(t1.date_added) >= ', $start_date)
                ->where('DATE(t1.date_modified) <= ', $end_date);
        $query = $this->db->get();
        $result = $query->result_array();                        
    if ($result) {
        $this->output->set_output(json_encode([
            'result' => 1,
            'data' => $query->result_array()
        ]));
        return false;            
    }else{
        $this->output->set_output(json_encode([
            'result' => 0,
            'error' => 'Failed Query'
        ]));
    }
}else{
        $this->output->set_output(json_encode([
            'result' => 0,
            'error' => 'Values Not Set'
        ]));
}
?>

Also if that isn't a function putting return false; won't return anything and is probably why it's running all the way through.

Answer 2

I would probably rewrite your code including a try/catch and forcing errors to show. Don't forget that in live servers most of the errors are set to hidden. So, no obvious errors are shown to the end user.

To debug

try {
   //put your code hear
} catch (\Exception $e) {
   die('An exception :- '. $e->getMessage());
}

If that doesn't still bring you enough information to debug, add following lines to the beginning of the php file.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Not to forget, once you resolved your issue remove or comment out above three error reporting lines. Because you don't want to show internal errors to end users.

Hope this helps you to debug your problem.

Cheers.

READ ALSO
doubts about write barrier as for java garbage collection

doubts about write barrier as for java garbage collection

I'm reading articles about Java GCI know write barrier is used when reference updated

144
add zero to each variable having a single number

add zero to each variable having a single number

I need to add zero to each variable if it is a single number

106
Combining two arrays side by side in Angular 7

Combining two arrays side by side in Angular 7

To combine two arrays side by side, I am following the below procedure but I get

124
Mongoose: Remove Document and all references completely

Mongoose: Remove Document and all references completely

I was wonderingI have a lot of coding to do with a function to remove a document from the database

109