Results 1 to 6 of 6
  1. #1
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Need some serious PHP help
    Ok, so while something worked on my local server on my PC, it turns out after going live with it, it doesn't work on my public server.

    PHP 4.3.10 running locally, 4.3.11 on the public server (if that makes a difference here).

    Basically I've got a hotel search form that runs off a datafeed. The only initial variable that matters that's being passed is the City. I've got some if/else statements that check for City/State/Country. Since city only exists, then one if statement selects all distinct cities and if only 1 city exists, it shows the hotels.

    If there's more than 1 match for a city then it let's the user know and gives the option of selecting the correct ciy (state and/or country). Once they click the right one the other if statements check if both state and country or just country exists and selects from the database accordingly.

    Just to give an idea of what's going on. That all works just fine. On my local server. And that's not the problem code.

    On my public server, a single city search works. A selectable city/state/country search returns the following error (when clicking the link):

    Fatal error: [] operator not supported for strings

    That error lies in this code which follows those previous if/else statements.

    PHP Code:
    while($inf mysql_fetch_array($res)){
       
    $city[] = $inf[city]; // line 41
       
    $state[] = $inf[state]; // line 42
       
    $country[] = $inf[country]; // line 43

    $res is the SQL query ($res = select......)

    If it's a US city, the error falls on line 42. If it's a non-US city, the error falls on line 43. It never fails on line 41.

    I did some searching on Google and found people with the same problems on various different things. I found a mention of changing:

    PHP Code:
    [] to [''
    Doing that for both line 42 and 43 clears up the error. But what it also does is disables the intercept option for when there's more than one match for a city.

    I hope this all makes sense, and I hope someone can help me figure this out as this is an urgent matter.

    And again, it all works fine locally, but not on the public server. So I'm thinking it's a server setting or something between the 2 PHP versions.

    Example URLs

    Mobile returns a single city: http://travel.example.com/hotels_res...ityname=Mobile
    Birmingham returns multiple (US and non-US): http://travel.example.com/hotels_res...ame=Birmingham

    Ignore all the trailing variables. They play no part in this problem.

    (URLs edited by request --Leader)
    Last edited by Leader; May 13th, 2005 at 05:45 PM. Reason: URLs edited by request

    Shawn Kerr (.com) | Disney World | SEC Football

  2. #2
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I'm not sure what the exact problem is, but one thing you said seems a little strange. You said you're entering your $query string into the mysql_fetch_array() function. This function only takes a resource variable from a mysql_query() function call. For debugging purposes, have you tried this:

    PHP Code:
    while($inf mysql_fetch_array($res)){
       print 
    "<pre>";
       
    print_r($inf);
       print 
    "</pre>";

       
    $city[] = $inf[city]; // line 41
       
    $state[] = $inf[state]; // line 42
       
    $country[] = $inf[country]; // line 43

    I use this quite often and it always helps me get a better picture of what's happening.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  3. #3
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I just had a thought, why not try this:

    PHP Code:
    while($inf mysql_fetch_array($res)){

       if(
    $inf[city])
       {
          
    $city[] = $inf[city]; // line 41
       
    }
       if(
    $inf[state])
       {
          
    $state[] = $inf[state]; // line 42
       
    }
       if(
    $inf[country])
       {
          
    $country[] = $inf[country]; // line 43
       
    }

    Not sure if that would help, but the errors might be coming from trying to add null values to your individual arrays.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  4. #4
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    It was because my server had register_globals on, my local php has it off.

    I knew it was not a code problem, it wouldn't work period. If it works on one server and not on the other, it has to be a configuration problem. I just wasn't sure what the config problem was.

    All works fine now.

    Shawn Kerr (.com) | Disney World | SEC Football

  5. #5
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Can someone please edit out the 2 "Example URLs" in my original post? While I needed them for "example" purposes I don't want the possibility of those particular URLs being crawled and indexed.

    Thanks.

    Shawn Kerr (.com) | Disney World | SEC Football

  6. #6
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    I've changed them to use "example.com" as the root URL.
    There is no knowledge that is not power. ~Hemingway

  7. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP question - include(file.php) with variables
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: September 4th, 2009, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •