hi.
i'm using the following code to list salutations from a salutations table. The user can select the salutation, but when my sql runs, it inserts the ID number. I really need it to insert the actual salutation. Any assistance would be appreciated. thx.
<label>
<?php
$result=mysql_query("select * from salutations");
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["SalutationID"];
$categoryname=$row["Salutation"];
$options.="<OPTION VALUE=\"$id\">".$categoryname.'</option>';
}
?>
<select name="Salutation">
<option value="0">< select salutation > <?php echo $options ?></option>
</select>
</label>
saving category name into db instead of id number
Moderator: General Moderators
Re: saving category name into db instead of id number
Sorry, but no. You should be using the ID number instead of the name. That's the whole point of having the ID numbers.
But whatever. Spoiler:
But whatever. Spoiler:
Code: Select all
<option value="the value you want in the database">the value you want to show to the user</option>Re: saving category name into db instead of id number
Actually, I don't agree. Using the text (aka a "natural language key") is preferable for things that don't change and that you'll always have to look up. There's little point in costing yourself a database JOIN every time you need to display the user's full name.tasairis wrote:Sorry, but no. You should be using the ID number instead of the name. That's the whole point of having the ID numbers.
Re: saving category name into db instead of id number
the reason i need to save the category name into the table instead of the id number is because i have other queries on other pages of the site looking up the info. for example.
name salutation
john dr
peter mr
that sort of thing.
the code that i'm using to list the salutations in a dropdown box do list the salutations but when posted to the database, i'm getting this.
name salutation
john 1
peter 2
how can i resolve this? thx.
name salutation
john dr
peter mr
that sort of thing.
the code that i'm using to list the salutations in a dropdown box do list the salutations but when posted to the database, i'm getting this.
name salutation
john 1
peter 2
how can i resolve this? thx.