1

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?

1
  • You first should learn how to run the SQL query and research PDO or MySQLi (the two recommended APIs in PHP). Secondly <?php $_PHP_SELF ?> won't do anything. First off what is $_PHP_SELF and secondly you aren't echoing it. Commented Jan 21, 2015 at 17:57

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Brock, there is also the short hand echo useful for templating: <?= $_SERVER['PHP_SELF'] ?>. This is equivalent to <?php echo $_SERVER['PHP_SELF']; ?>.

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.