0

Here is my code for populating data into dropdown list from mysql database

<select name="robes">
  <?php
  $result = mysql_query("SELECT * FROM robes ORDER BY Classement ASC")or die(mysql_error());
  while ($row = mysql_fetch_array($result)) {
    $color = $row["color"];
    ?>
    <option value="<? echo $row['Id_robe']; ?>"><? echo $color;?></option>
    <?php
  }?>
</select>

now my problem that there is no data shown and no error message also.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
Davina
  • 21
  • 7
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Aug 10 '16 at 11:57
  • Have you looked at your PHP Error Log? – RiggsFolly Aug 10 '16 at 12:00
  • Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Aug 10 '16 at 12:01
  • @RiggsFolly thanks for the advice, actually I'm studing pdo connection but I just need this for a specific thing – Davina Aug 10 '16 at 12:18

2 Answers2

0

First check Short tag open or not in php.ini if not then SET

short_open_tag=On

but better is to use

 <select name="robes">

        <?php
        $result = mysql_query("SELECT * FROM robes ORDER BY Classement ASC")or die(mysql_error()); 

        while ($row = mysql_fetch_assoc($result)){ 
        ?>
        <option value="<?php echo $row['Id_robe'];?>"><?php echo $row["color"];?></option>

        <?php
        } 
        ?>
    </select>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
  • 1
    Why should the OP "use this code"? A **good answer** will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO that may find this question and be reading your answer. – RiggsFolly Aug 10 '16 at 11:58
0

Can you please check if php short tag is enabled? Or Use full php tag like

<?php instead of <?
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Kashyap
  • 381
  • 4
  • 10