Home Trying to pull data and input it into a drop-down menu but it doesn't seem to pull anything? Am I missing something?
Reply: 1

Trying to pull data and input it into a drop-down menu but it doesn't seem to pull anything? Am I missing something?

Thomas
1#
Thomas Published in 2018-02-14 16:43:13Z

I have the connection etc previous to this; the column I'm trying to pull is called course_name from database course - not sure if I'm missing something?

        <label for="course">Related Course</label>
        <select name="course" class="form-control">

        <?php 

        $result = mysql_query($conn, "SELECT course_name FROM course");

        echo "<select name='course_name'>";
        if (!$result) { 
            die('Invalid query: ' . mysql_error());
        } else {
        while ($row = mysql_fetch_array($result1)) {
            echo "<option value='" . $row['course_name'] ."'>" . $row['course_name'] ."</option>";
                }
        }
        echo "</select>";

        ?>

        </select>
Claudiu D.
2#
Claudiu D. Reply to 2018-02-14 17:39:35Z

So from your comments below you are using mysqli not mysql php extension, so your code should look like this

   <?php 

    $result = mysqli_query($conn, "SELECT course_name FROM course");

    echo "<select name='course_name'>";
    if (!$result) { 
        die('Invalid query: ' . mysqli_error($conn));
    } else {
    while ($row = mysqli_fetch_array($result)) {
        echo "<option value='" . $row['course_name'] ."'>" . $row['course_name'] ."</option>";
            }
    }
    echo "</select>";

    ?>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.521209 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO