I am wanting to create a drop down menu that displays one value in a database inside the form, but passes another value when the form is submitted.
For example I have a table named users with entries:
-----------------------------------
ID | UserName
-----------------------------------
1 BobG
-----------------------------------
2 JaneD
I want the drop down menu to list the names, but when JaneD is selected I want to pass the value "2" not "JaneD"
My current code is
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//Get data for UserName Dropdown
$query="SELECT UserName FROM users";
$result1=mysqli_query($dbc, $query);
$options="";
while ($row=mysqli_fetch_array($result1)) {
$UserName=$row["UserName"];
$options.="<OPTION VALUE=\"$UserName\">".$UserName;
}
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="UserName">Select User:</label><SELECT NAME="UserName" id="UserName">
<OPTION VALUE=0 selected="selected">
<?=$options?>
</SELECT> </div>
<div class="field_submit"><input type="submit" value="submit" name="submit" /></div>
</form>
Thanks for looking.