0

I have been trying to create a form with dynamic dropdown list fetching data from MYSQL. My database is fine without errors. I have been trying to make it work, the page does not take data from mysql, what's wrong with my code? The table is called 'table' and the column is called "name", there are three inputs "name1", "name2", "name3", but they are not fetched from mysql. Thank You.

<?php
    $link=mysqli_connect("localhost","root","");
    mysqli_select_db($link,"dropdown");
    if (!$link) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
        exit;
    }
    echo "Connection is active" . PHP_EOL;
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
        <form name="form" action="" method="post">
            <select>
                <?php
                $res = mysqli_query($link, 'SELECT name FROM table');
                while($row = mysqli_fetch_array($res))
                {
                    ?>
                    <option><?php echo $row['name'];?></option>
                    <?php
                }
                ?>
            </select>
        </form>
    </body>
    </html>
Hubert Kubasiewicz
  • 365
  • 1
  • 3
  • 16
  • What results are you getting as opposed to the desired ones? You didn't say that. – Funk Forty Niner Oct 05 '19 at 21:14
  • I am getting nothing an empty form, but I getting the info that connection is active. – Hubert Kubasiewicz Oct 05 '19 at 21:15
  • 1
    `table` is a mysql reserved word. Either rename it to something other than one, or encapsulate it inside ticks `\``. `mysqli_error($link)` would have helped you here. – Funk Forty Niner Oct 05 '19 at 21:21
  • Had I known this from the beginning, it would have been a different story. I already voted to close as unclear. – Funk Forty Niner Oct 05 '19 at 21:21
  • @Nick (Seeing the close) I deleted my answer and added another duplicate for this. It should have been that one to close with, but no biggie. Yours does address it. I retracted my vote as unclear btw. That's why my name isn't in the ones who voted. – Funk Forty Niner Oct 05 '19 at 22:17
  • [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Oct 06 '19 at 10:07

0 Answers0