why is my program working in my test environment but not my live site?

I have a very strange problem that I could really use some insight on. I have a site that is running perfectly in my test environment. This is on my server and the program is for inventory, it allows the user to select a shelf location, then narrow it down by shelf area. Again, this works perfectly in the test environment. I also have a live environment, where this exact same site will not work correctly, I keep getting data.id is undefined when I run Firebug. The really odd thing is, when I add console.log(data) to my ajax success function, it shows me all the data. I have also done this for the test environment and the only difference that I see is that it groups all the id's together and then the locations. In the live environment it shows id=1, location=1, id= 1,2 location = 1,2 etc. in the test environment is shows id=1,2,3 etc location=1,2,3, etc.

Why is it doing this????

I am not sure what parts of the code you may need to see to help with this issue, but I can post whatever you need to see.

Edit: this is only happening on one ajax call, all the others are working correctly. The domain name is the same except one has testbcos and the other is just bcos. Here is the code for the ajax call:

// Inventory verification section
$("#area").change (function(){
$("#acctRecords tbody tr").remove();
$('#label').show();
$('#label2').show();
$('#location').show();
$('#section').show();

$.ajax({
    type: "POST",
    async: true,
    url: "area.php",
    dataType:"json",
    data: ({area: $('#area').val()}),
    success: function(data) {
                console.log(data);
    $('select#location').empty();   
    $('select#location').append('<option value="0">Select Option</option>');
    $('select#section').empty();    
    $('select#section').append('<option value="0">Select Option</option>');

    //Populate options of the second dropdown
            for(var x=0;x<data.location.length;x++)
                {    
                $('select#location').append('<option value="'+data.id[x]+'">'+data.location[x]+'</option>');
        $('select#section').append('<option value="'+data.id[x]+'">'+data.location[x]+'</option>');
            } //end of each function

This is the exact same code for the live and test environments.

Edit #2: I don't know if this will help, but here is the area.php file.

$conn = db_connect();
session_start();
$area = $_POST['area'];
$x = 0;
$return_arr = array();

$result = $conn->query ("SELECT location_id, location FROM location where location like '$area%' ORDER BY location");

            $num_rows = $result->num_rows;

if($num_rows > 0)
{ 
            while ($row = $result->fetch_assoc())
            {
                $idArray[$x] = $row['location_id'];
                $locationArray[$x] = $row['location'];
                $x++;

            $location = array('id' => $idArray,
                'location' => $locationArray
                );

            array_push($return_arr,$location);
            }

}

$conn->close();

echo json_encode($return_arr);

Answers


It sounds like area.php is returning the data differently. Are sure the PHP files are up to date on the live server?


It turns out that in the area.php file, I do not need to use the array_push function:

array_push($return_arr,$location);

When I changed it to return just $location,:

echo json_encode($location);

everything works fine. Thanks to all for the assistance.


Need Your Help

SQL output not showing properly

php sql

I have a code that is up and running and for some reason just suddenly stops working, whenever I do a Search, this is the only result I am getting and table does not show: Searched For: pam