An "Undefined Variable" Problem - or even more simple?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SuperFool
    New Member
    • Jun 2007
    • 4

    #1

    An "Undefined Variable" Problem - or even more simple?

    This has got to be one of those questions only a serious newbie would come up with....

    Basicly: I select all the city names in the table and turn them into a pull down menu (code below)
    [code=php]
    print "<form action=\"update-city.php\" method=\"post\" name=\"theform\ ">";
    print "<SELECT id=\"city\">\n" ;

    while ($row =mysql_fetch_ob ject($result)) {

    foreach ($row as $col=>$val){
    print "<option value=\"\n";
    print $val ;
    print "\">";
    print $val ;
    print "</option>\n";
    }
    }
    print "</select>\n";
    ?>
    <!-- Finish the form -->
    <input type="submit" name="action" value="Update City">
    </form>
    [/code]

    Then I'm playing with it (working up the way to update) but all the variables seem empty. (Here's code for a simple table)

    [code=php]
    $sql = "SELECT city_name, city_default_zi p, seatac_price, boeing_price FROM char_city WHERE city_name = ('$city')";
    $result = mysql_query($sq l)
    or die(mysql_error ());

    <table border="1">
    <tr>
    <td>City Name</td>
    <td>Default Zip Code</td>
    <td>Seatac Price</td>
    <td>Boeing Price</td>
    </tr>
    <?
    while ($row =mysql_fetch_as soc($result)) {
    $lshit[] = $cityList[$row['id']] = $row['city_name'];
    $shit[] = $cityList[$row['id']] = $row['city_default_z ip'];
    $mshit[] = $cityList[$row['id']] = $row['seatac_price'];
    $bshit[] = $cityList[$row['id']] = $row['boeing_price'];
    print "<tr>\n";

    foreach ($row as $col=>$val){
    print "<td>\n";
    print $val ;
    print "</td>\n";

    }//end for each
    print "</tr>\n";
    }//end while
    ?>
    </table>[/code]

    As you can see - it doesn't get any more simple.... So why doesn't it work? And what's really got me whacked out... Why doesn't it work in IE 6 or 7 - Yet works just fine in FireFox?

    I read the forum sticky before posting so for some more info...
    I installed...
    error_reporting (E_ALL);
    ini_set('displa y_errors', True);

    Which now gives me "Notice: Undefined index: city in /home/content......" For both IE and FireFox - but Firefox at least still fills out the table...

    I also tried....[code=php]
    $sql = "SELECT city_name, city_default_zi p, seatac_price, boeing_price FROM char_city WHERE city_name = ('$_POST[city]')";[/code]
    (and a few variations of where to put the quote)
    and
    [code=php]$city = $_POST['city'];
    $sql = "SELECT city_name, city_default_zi p, seatac_price, boeing_price FROM char_city WHERE city_name = ('$city')";[/code]

    Plus: I pulled the following out of a book regarding the global variables....
    foreach [code=php]($_POST as $key => $value) {
    $$key = $value;
    }[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    Watch. I'm missing some little punctuation mark or something -

    Anybody see my problem?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, SuperFool. Welcome to TSDN!

    What is the problem you are having? If it's working in one browser, but not another, then the problem is not the PHP (though it could be the HTML).

    Comment

    • SuperFool
      New Member
      • Jun 2007
      • 4

      #3
      Originally posted by pbmods
      Heya, SuperFool. Welcome to TSDN!

      What is the problem you are having? If it's working in one browser, but not another, then the problem is not the PHP (though it could be the HTML).
      Thanks.

      I'm upset with myself over how much time I'm spending on this problem - however the more I learn about PHP the more excited I get about the possibilities.

      My problem is that while all variations I've created on this attempt work fine in FireFox - they come up blank in both IE 6 & 7, which unfortunately runs about 88% of the visitors, so as cool as it is for my friend - it's useless if IE can't see it.

      Right now, I'm just trying to make it work - I'm able to make it pretty later. It's just trying to get a grasp on it with nothing more than me and a couple books is pretty difficult. Maybe if I started on chapter 1... but then that wouldn't be me - I'm more foolish than that.

      Back to the subject at hand....
      When I input the display error code bit I found in the sticky for this forum - I keep getting told "Notice: Undefined variable: name in /home/content...blah, blah"

      So I guess it's a matter of trying to print every variable name I can come up with. Well, that's a decent way to learn I guess. I can't imaging that I have to build a giant list of IF THEN statements for every possible city that could be chosen from the pull down menu - that seems to just contradict the purpose.

      I'll figure it out - I just welcome a place to ask some questions occasionally.
      Thanks for your insight

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, SuperFool.

        Instead of mysql_fetch_obj ect(), try using mysql_fetch_ass oc().

        mysql_fetch_obj ect() returns an object, not an array.

        As for why it's coming up blank in IE, are you accessing the same server on each computer? In other words, are you typing 'localhost' in the address bar, but using a different computer?

        Comment

        • SuperFool
          New Member
          • Jun 2007
          • 4

          #5
          Hello pbmods

          Originally posted by pbmods

          Instead of mysql_fetch_obj ect(), try using mysql_fetch_ass oc().

          mysql_fetch_obj ect() returns an object, not an array.
          Nope - No change. I used object a while ago because assoc gave me duplicate results of everything.

          As for why it's coming up blank in IE, are you accessing the same server on each computer? In other words, are you typing 'localhost' in the address bar, but using a different computer?
          I'm doing everything on the server - not using my local machine for anything but Dreamweaver - well that and FTP to upload it to the server.

          Accessing the db is set up through include commands - so no danger of mistyping anything from one to the other.

          And now, I've managed to play with it enough to break FireFox for this now as well.

          I've added a table, where I've tried to list out every variable I can think of, but of course they all come up blank too.

          thanks again

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, SuperFool.

            Ok, let's start from the beginning. What happens when you:

            [code=php]
            var_dump($city) ;
            [/code]

            If $city is empty, you will get no results from your query, unless there are entries where city_name is empty.

            Next: [code=php]print($sql);[/code] and try manually running that query in your MySQL client. Do you get any results?

            Next: [code=php]var_dump($resul t);[/code] and make sure that mysql_query() is returning the proper value.

            Next: [code=php]or die(mysql_error ());
            // Add this line:
            print('!');[/code] after your die() statement to make sure that your code is executing properly.

            At this point, the HTML in your script HAS to be getting output.

            Next, make sure your mysql_query returned the proper results. [code=php]while($row = mysql_fetch_ass oc($result)) {
            // Add this line:
            print('<pre>' . print_r($row, true) . '</pre>');
            .
            .
            .
            print('<hr />');
            }[/code]

            That's my reaction at this point. Somewhere, something isn't doing what it's supposed to. Welcome to unit testing. Fun stuff, huh?

            Comment

            • SuperFool
              New Member
              • Jun 2007
              • 4

              #7
              Previous Post Deleted........ ...... I'll try this again.....

              Comment

              Working...