Use of radio button with select data from mysql table

Hi there…

I like to get user input based on use of two radio buttons, where one gives an option of say ‘yes’, and next to it, is a select dropdown displayed with data from a mysql table.
The other radio button gives the option to register the data to the same table whose data is displayed in the dropdown above.

Typical example is if I like to register a product but like to add its supplier (whose details are in are supplier’s table) and if supplier is new, the same interface can allow to register this supplier.

The problem I am facing is how to get the actual data displayed in the dropdown posted to the products table rather than the value (existing in this case) of the radio button.

Snippet is below:

<input type="radio" name="supplier" value="existing" <?php if (isset($_POST['supplier']) && ($_POST['supplier'] == 'existing'))
    echo 'checked="checked"'; ?> /> Existing =></td>
                <td><select name="supplier">
                        <option>Select One</option>
                        // Retrieve all the suppliers and add to the pull-down menu.
                        $q = "SELECT sup_id, sup_name FROM suppliers ORDER BY sup_name ASC";
                        $r = mysqli_query($dbc, $q);
                        if (mysqli_num_rows($r) > 0) {
                            while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) {
                                echo "<option value=\\"$row[0]\\"";
                                // Check for stickyness:
                                if (isset($_POST['existing']) && ($_POST['existing'] == $row[0]))
                                    echo ' selected="selected"';
                                echo ">$row[1]</option>\
<input type="radio" name="supplier" value="new" <?php if (isset($_POST['supplier']) && ($_POST['supplier'] == 'new'))
                            echo ' checked="checked"'; ?> />
                    New Supplier =>

Grateful for any insight.

… make the value the name?

                                echo "<option value=\\"$row[0]\\"";


                                echo "<option value=\\"$row[1]\\"";



Am confused on how I can fit that in my snippet. Some tip please?


You… change the line in your snippet that matches the first block, and make it into the second block.