0

I am having a problem displaying data from MYSQL into drop down box.

Output:

<html>
<body>
    <form name=displayQuestion>
        Survey Categories : 
        <select name="surveyCategory">
        <option> Choose Survey Category </option>
        <?php
            $surveyQuery = "SELECT survey_id, survey_name FROM surveys";
            $result = mysql_query($surveyQuery) or die (mysql_error());
            while($menu=mysql_fetch_assoc($result)){
                echo "<option value=$menu[survey_id]>$menu[survey_name]</option>";                  
            }
        ?>
    </select>
    </form>
</body>
</html>
1
  • First off, mysql_query has been deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. That said, where are you establishing your connection to the db? Add that to your question. Commented Dec 15, 2013 at 5:34

2 Answers 2

1

no reason to use that ugly formatting:

echo '<option value="' . $menu['survey_id'] . '">' . $menu['survey_name'] . '</option>'; 
Sign up to request clarification or add additional context in comments.

2 Comments

Access field value with simple quotes $menu['survey_name']
Your code have syntax error: '<option value="'> . should be '<option value="' .
1

You need put your option value within quotes and access array with simple quotes like as:

echo "<option value=\"$menu['survey_id']\">$menu['survey_name']</option>";   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.