r94yan
r94yan

Reputation: 15

Adding a drop down list to a table, that is linked to a SQL database

I have an insert script and an update script, both separate. The script submits the data to the database, and adds or updates the database. The scripts work within a table.

Part of the code:

<form method="post" action="<?php $_PHP_SELF ?>">
<table width="750" border="0" cellspacing="1" cellpadding="5">

<tr>
    <td width="100">Staff ID</td>
    <td><input name="staff_id" type="text" id="staff_id">
               <th>
 Enter Desired ID
               </th>
    </td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>

I want to add some options to the table, like a drop down menu. How would I go about that?

Upvotes: 1

Views: 96

Answers (1)

Brock Amhurst
Brock Amhurst

Reputation: 497

Use the select tag, like so:

<select name="myselect">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Source: W3 Schools Select tag

The value selected will be available to your PHP script as $_POST['myselect'] or whatever name you choose for the select tag.

Also, as Devon mentioned in his comment, make sure your form is implemented properly and following PHP rules. If you're posting the form to the same page the form is on, you need to ensure its in a PHP file and not an HTML file. Also, change the "<?php $_PHP_SELF ?>" part to "<?php echo $_SERVER['PHP_SELF']; ?>" and ensure all the HTML in your file is either echoed or outside the <?php ?> tags

Upvotes: 1

Related Questions