Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:21:45+00:00 2026-05-25T14:21:45+00:00

I created a database with 3 tables being spusername, splocation, sprecord. spusername has id,

  • 0

I created a database with 3 tables being spusername, splocation, sprecord. spusername has id, splocation_id, lastname, firstname. I want to be able to have a drop down menu that has pulled id, lastname, firstname from the database, and within the pulldown it only shows a list of all the names being lastname,firstname. then once I select a person I have another drop down that has types of training in it. then when I hit submit it will generate a record in another table with the persons id and training record. so when I do a search it will pull up the user and the training records for that person…. I have already created a submit page in a .php that sends lastname, firstname, splocation_id for new users and I think I can create a search that does what I want it to, but I have never made a data entry doing a pulldown that has values generated from the database.

EDIT Code: With help from Vegard’s coding I got this, and now it works great after a few trial and errors. Thank You!

Code:

<?php 
    if (isset($_REQUEST['Submit'])) { 
    $sql = "INSERT INTO $db_table(spusername_id,sptraining_id) values ('".mysql_real_escape_string(stripslashes($_REQUEST['spusername_id']))."','".mysql_real_escape_string(stripslashes($_REQUEST['sptraining_id']))."')";
    if($result = mysql_query($sql ,$db)) { 
    echo '<h1>Thank you</h1>Your information has been entered into the database<br><br>'; 
    } else { 
    echo "ERROR: ".mysql_error(); 
    } 
    } else { 
?> 
<h1>Add Training Information To Database</h1><hr> 
<br><br>
<form method="post" action=""> 
<select name="spusername_id">
    <option value="default">Select Employee</option>
<?php
    include("connectspusers.php"); /*file where you have stored your DB conn. settings*/
    $result = mysql_query('SELECT id, lastname, firstname FROM spusername ORDER BY lastname ASC') or die (mysql_error()); 

    while ($row = mysql_fetch_array($result)) {
        echo '<option value="' . $row['id'] . ' ' . $row['lastname'] . ' ' . $row['firstname'] . '">' . $row['lastname'] . ', ' . $row['firstname'] . '</option>';
    }
?>
</select>

<select name="sptraining_id">
    <option value="default">Select Training</option>
<?php
    include("connectsptraining.php"); /*file where you have stored your DB conn. settings*/
    $result = mysql_query('SELECT id, trainingtype, level FROM sptraining ORDER BY level ASC') or die (mysql_error()); 

    while ($row = mysql_fetch_array($result)) {
        echo '<option value="' . $row['id'] . ' ' . $row['trainingtype'] . ' ' . $row['level'] . '">' . $row['trainingtype'] . ' - ' . $row['level'] . '</option>';
    }
?>
</select>
<br><br>
<input type="submit" name="Submit" value="Submit"> 
</form> 
<?php 
} 
?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:21:45+00:00Added an answer on May 25, 2026 at 2:21 pm

    Something like this?

    <select name="pulldown1">
        <option value="default">Choose an option</option>
        <?php
        include("connect.php"); /*file where you have stored your DB conn. settings*/
        $result = mysql_query('SELECT id, lastname, firstname FROM spusername ORDER BY firstname ASC') or die (mysql_error()); 
    
        while ($row = mysql_fetch_array($result)) {
        echo '<option value="' . htmlentities($row['id'], ENT_QUOTES) . ' ' . htmlentities($row['lastname'], ENT_QUOTES) . ' ' . htmlentities($row['firstname'], ENT_QUOTES) . '">' . htmlentities($row['lastname'], ENT_QUOTES) . ', ' . htmlentities($row['firstname'], ENT_QUOTES) . '</option>';
        }
        ?>
    </select>
    
    <select name="pulldown2">
        <option value="default">Choose and option</option>
        <?php
    
        $result = mysql_query('SELECT traingtype FROM trainingtable ORDER BY trainingname ASC') or die (mysql_error()); 
    
        while ($row = mysql_fetch_array($result)) {
            echo '<option value="' . $row['trainingtype'] . '">' . $row['trainingtype'] . '" "' . $row['lastname'] . '</option>';
        }
        ?>
    </select>
    

    This will result in two dropdown menus where the first dropdown lists the users last- and firstname separated by a comma+space and the second will list the different types of training. The ID filed is only sendt via the variable, but not displayed to the user.

    When pulling the values from the variable in pulldown1, just use explode:

    $userdetails = $_POST['pulldown1'];
    $values = explode(" " $userdetails);
    $ID = $values[0];
    $lastname = $values[1];
    $firstname = $values[2];
    

    Haven’t tested the code so it might need tweaking, and ofcourse you need to change the variable names corresponding to your actual db rownames.

    Edit: In your code, you have to use $row and not $row2.

    Secondly, instead of this:

    <option value='{$id}'>{$lastname},{$firstname}</option>
    

    use this:

    <option value="' . $row['id'] . '">' . $row['lastname'] . ', ' . $row['firstname'] . '</option>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I have designed database tables (normalised, on an MS SQL server) and created a
I have an SQLite database. I created the tables and filled them with a
Looking through my database tables, I'm seeing that the created field is invariably being
I have a database with 2 tables; Users and Revisions. Revisions has multiple one-to-many
iv created a database with some tables and populated them using SQL server 2008,
I've created a view on 3 tables in my database, they are as follows:
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have a Classic ASP site, that requires some database tables to be emptied
I created a simple databse using Oracle that has several tables and a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.