How to use select to insert into database

I would like to add a select option in my html form where the user can select options for their plan… I have heard of populating drob down box from the database but can i just do a basic drop down box as follows


<select id='subscribe'>
   <option value="1">primer level </option>
  <option value="2">level 1 </option>
</select>

Does the select id correspond with the name in the database column? And i guess in my table… i should see either a 1 or 2 instead of the word primer or level 1

You can add the drop-down options manually if you want to.

The select element needs a name attribute.

Use whatever value you want to be returned by the input.

So if I were to set a name attribute, that should insert into the database? What is an id? Is that similar to having a class? Thanks

An ID is a unique identifier for an element.

It can be used in a css selector like a class, but that is not recomended, due to the very high specificity of id selectors.
One use is as a target for anchors in a page, so you can have a link “jump” to a specific part of the page, Eg:

<a href="#subscribe">Go to Subscription</a>

But in the context of form inputs, it is most commonly used to link labels to inputs, Eg:

<label for="subscribe">Choose Subscription</label>
<select id='subscribe' name="level">
   <option value="1">primer level </option>
  <option value="2">level 1 </option>
</select>

The name will determine the key of the input in the POST array.
So in the above example where the name is level you would have $_POST['level'] in the post array with the chosen value as its value.

Thanks, I think I understand what is going on here.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.