Jump to content

Jump menu options to write to database


Gilmore

Recommended Posts

I'm trying to update a CMS that someone made for me ages ago by adding a 'member type' field in the 'members' table.

I've managed to build in the new field and you can enter the memberType number manually (1 to 3) in the admin section.
The Member Types are:

1 = Manager
2 = Supervisor
3 = Floor Manager

And the input box looks like this:

[code]<input name="memberType" type="text" id="memberType" value="<? echo $_POST['memberType'] ?>">[/code]

At the moment I enter the number manually, but I'd rather do it with a jump menu.

          [code]<select name="select">
              <option value="3">Floor Manager</option>
              <option value="2">Supervisor</option>
              <option value="1">Manager</option>
          </select>[/code]

I would like for the person using the CMS to see the memberType and when they select a type, it writes the relating number to the database.

Does that makes sense?

I'd appreciate any help.

TIA.
Link to comment
https://forums.phpfreaks.com/topic/29093-jump-menu-options-to-write-to-database/
Share on other sites

I'd create a separate table in my database called memberTypes, it has two columns, the first is called id, is unique, and is auto incrementing and the second is called type.

Insert the rows into it
1 Manager
2 Supervisor
3 Floor Manager

Then on your page, you want to generate the dropdown menu like this:

[code]<?php
// Print the start of the select code
echo "<select name=\"type\" id=\"type\">\n";

// Query the database for values
$sql = "SELECT * FROM memberTypes";
$types = mysql_query($sql) or die ("Can't execute: $sql<br>\n<br>\n" . mysql_error());

// Output a row for each field in the database
while ($row = mysql_fetch_array($types, MYSQL_ASSOC)){
  echo "<option value=\"{$row['id']}\">{$row['type']}</option>\n";
}

// Print the end of the select code
echo "</select>\n";
?>[/code]

This way, you can add as many rows as you like to the memberTypes table, in case you need to create new types in the future and they'll appear in the page without having to re-write any php.

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.