1

I have four drop down boxes which display information from the database but it's only displaying two of the four. http://www.cupboard2stomach.com/php/get.php?dropdown1=bread&dropdown3=chicken&Submit=Submit This is what it currently looks like.

Is there something wrong with my code?

Ingredient 1:<select name= "dropdown1" id = "drop1"/>
    <?php
    while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
    ?> 
    <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
    <?php
    }
    ?>

    Ingredient 2:<select name = "dropdown2" id = "drop2"/>
    <?php
    while ($line = mysql_fetch_array($result2, MYSQL_ASSOC)) {
    ?> 
    <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
    <?php
    }
    ?>

    Ingredient 3:<select name = "dropdown3" id = "drop3"/>
    <?php
    while ($line = mysql_fetch_array($result3, MYSQL_ASSOC)) {
    ?> 
    <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
    <?php
    }
    ?>


    Ingredient 4:<select name = "dropdown4" id = "drop4"/>
    <?php
    while ($line = mysql_fetch_array($result4, MYSQL_ASSOC)) {
    ?> 
    <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
    <?php
    }
    ?>
Vinicius Garcia
  • 1,740
  • 4
  • 30
  • 54
Lawrence Smith
  • 327
  • 1
  • 6
  • 15
  • $result3 and $result4 are you sure they are correct mysql resource? – Robert Apr 29 '13 at 13:53
  • Are you sure `$result1`,`$result2`,`$result3` and `$result4` are not empty? – Vinicius Garcia Apr 29 '13 at 13:54
  • 1
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Apr 29 '13 at 13:56
  • http://validator.w3.org/check?uri=http%3A%2F%2Fwww.cupboard2stomach.com%2Fphp%2Fget.php%3Fdropdown1%3Dbread%26dropdown3%3Dchicken%26Submit%3DSubmit&charset=%28detect+automatically%29&doctype=Inline&group=0 – Quentin Apr 29 '13 at 13:57

4 Answers4

3

You are attempting to use XML style self-closing tag syntax for your select elements (<select />) this is wrong and browsers will perform error recovery by ignoring the /.

Consequently, the end tags (</select>) are missing from all your select elements. So you are trying to place your subsequence select elements inside the first one.

Even if you could use self-closing tag syntax on arbitrary elements, the option elements need to be descendants of the select element to which they belong!

A validator would have picked this up for you.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

It's because you're not closing your select boxes

For example, change to this:

Ingredient 1:<select name= "dropdown1" id = "drop1"/>
    <?php
    while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
    ?> 
    <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
    <?php
    }
    ?>
</select>
What have you tried
  • 11,018
  • 4
  • 31
  • 45
1

close your select tag

    Ingredient 1:<select name= "dropdown1" id = "drop1"/>
        <?php
        while ($line = mysql_fetch_array($result1, MYSQL_ASSOC)) {
        ?> 
        <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
        <?php
        }
        ?>
       </select>
        Ingredient 2:<select name = "dropdown2" id = "drop2"/>
        <?php
        while ($line = mysql_fetch_array($result2, MYSQL_ASSOC)) {
        ?> 
        <option value="<?php echo $line['ingredientname'];?>"> <?php echo $line['ingredientname'];?> </option>
        <?php
        }
        ?>
</select>
Harshit Tailor
  • 3,261
  • 6
  • 27
  • 40
  • The select must end with `>`, not with `/>`. – Vinicius Garcia Apr 29 '13 at 13:59
  • @HarshitTailor If I wanted my drop down boxes to have one blank row at the top so they display nothing at first then do you know what I would need to change? I know I could make an empty row in the database table but that would be bad practice. – Lawrence Smith Apr 29 '13 at 14:03
0

It is because of select it ends with /> it should end with >

w3c validator gives error

 self-closing syntax (/>) used on a non-void HTML element. Ignoring the slash and treating as a start tag.

Next time you should use http://validator.w3.org/ to check your code.

Robert
  • 19,800
  • 5
  • 55
  • 85
  • Not really. It is because the `` is missing (which might be because the OP is attempting to use the `/>` syntax instead) – Quentin Apr 29 '13 at 13:58