0

I'm redesigning my site to base it off WordPress, and in the process, I need to import some PHP/jQuery. I find that it works fine on the original page but not the new one.

Here are the results of the JSON dumps:

  • Old - empty as it should be because no data
  • New - doesn't like using $_POST['club'] to import

The code in both instances is:

<script type="text/javascript">
    $(document).ready(function() {
        $.ajax({
            type: "post",
            url: "eventinfo.php",
            data:  $('#club').serialize(),
            success: function(data) {
                $('#right_inside').html('<h2>' + $('#club').val() + '<span style="font-size: 14px"> (' + data[0].day + ')</h2><p>Entry: ' + data[0].entry + '</p><p>Queue jump: ' + data[0].queuejump + '</p><p>Guestlist closes at ' + data[0].closing + '</p>');
                },
            dataType: "json"
        });
    });

    $('#club').change(function(event) {
        $.ajax({
            type: "post",
            url: "eventinfo.php",
            data:  $(this).serialize(),
            success: function(data) {
                $('#right_inside').hide().html('<h2>' + $('#club').val() + '<span style="font-size: 14px"> (' + data[0].day + ')</h2><p>Entry: ' + data[0].entry + '</p><p>Queue jump: ' + data[0].queuejump + '</p><p>Guestlist closes at ' + data[0].closing + '</p>').fadeIn('500');
                },
            dataType: "json"
        });

    });
</script>

And my eventinfo.php is:

<?php

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

include('guestvibe_functions.php');
connect();


$night = $_POST['club'];
$night = mysql_real_escape_string($night);

$query = "SELECT * FROM nights WHERE name = '" .$night. "'";

    $result = mysql_query($query);
    $items = array();

    if($result && mysql_num_rows($result) > 0) { 
        while ($row = mysql_fetch_array($result)) { 
        $items[] = array("entry"=>$row['entry'], "day"=>getLongDateString($row['day']), "queuejump"=>$row['queue jump'], "closing"=>$row['closing']);
        }
    } 

    mysql_close(); 
    // convert into JSON format and print

    echo json_encode($items);
?>

It's late so I hope I've explained this alright. Any ideas what's wrong?

EDIT

I should add that both are on the same server / hosting plan. The new one is just one directory up.

Sebastian
  • 3,548
  • 18
  • 60
  • 95

2 Answers2

0

see this answer for clues

I think you probably have either a newer version of PHP or different server settings on the new PHP server.

Community
  • 1
  • 1
Chris Morley
  • 2,426
  • 2
  • 19
  • 20
0

I see two possibilities.

The first is that on the new site the club= variable is not populated by AJAX when in the old site it is. Then you must discover why the serialize() does not include a variable called 'club'.

The second is that the club= variable wasn't necessarily populated even in the old site, and you just didn't get the notice warning.

In this case, modifying the code from

$night = $_POST['club'];

in

$night = isset($_POST['club']) ? $_POST['club'] : '';

should solve the problem.

UPDATE

I checked the site, but the eventinfo URL I received is different from the one you quote. What my Firefox got was:

 http://www.guestvibe.com/wordpress/eventinfo.php

...which results in a 404 Error.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • Thanks for your reply. I can confirm that serialize() does include a variable called club because it can be printed fron jQuery. Where the problem occurs is passing that variable to eventinfo.php in order to return the database values that correspond to 'club'. Where did you get that eventinfo URL from? 404 is understandable given that it doesn't exist. – Sebastian Aug 23 '12 at 11:44