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

  • SEARCH
  • Home
  • 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 8655617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:04:31+00:00 2026-06-12T15:04:31+00:00

I have 3 drop-down boxes, which work great. I’m able to choose the values

  • 0

I have 3 drop-down boxes, which work great. I’m able to choose the values from 3 different tables and submit/save to a summary table via the various table ID’s. However, I’d also like to be able to edit these values in the same drop down fields. I have an edit function that sends the summary table ID to a $_GET function to identify the row. The values currently show up in 3 text boxes, but I’d rather they populate into the same drop-down fields instead. I’m unable to get the options syntax correct.. I’m thinking I need a “selected” option in there somewhere. I only want the proj_hours column to be updated, but still want all 3 drop-down’s populated with values.

I hope that makes sense? I want to get rid of the text boxes.

Most recent code:

<?php

    // Connect to server and select database.
    $link = mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    //grabs ID from the initial edit submit 
//grabs ID from the initial edit submit 
    if(isset($_GET['id']))
echo "<pre>Value of \$_GET:</br>";print_r($_GET);echo"</pre>";  
    {
        $summary_id = $_GET['summary_id'];
        $res = mysql_query("SELECT *
                    FROM summary S
                    JOIN projects P ON S.proj_id = P.proj_id
                    JOIN departments D ON D.dept_id = S.dept_id
                    JOIN hours H ON H.hours_id = S.hours_id
                    WHERE S.summary_id = '$_GET[id]'
                    ORDER BY D.dept_id
                    LIMIT 0 , 30");

        $rows = mysql_fetch_array($res);

//echo "<pre>Value of \$rows:</br>";print_r($rows);echo"</pre>";  //was using to check what's going on 
        }

//submits the edited values, does a join to find out what's what, and inserts the correct digits into the summary DB        
    if (isset($_POST['btnsubmit']))  
echo "<pre>Value of \$_POST:</br>";print_r($_POST);echo"</pre>";
    {
//echo "<pre>Value of \$_POST:</br>";print_r($_POST);echo"</pre>";
        $summary_id     = $_POST['summary_id'];     
        $nclarity_id    = $_POST['nclarity_id'];
        $nproj_hours    = $_POST['nproj_hours'];
        $ndept_name     = $_POST['ndept_name'];

        $sql1           = "UPDATE summary S
                            SET S.hours_id = (
                            SELECT H.hours_id  
                            FROM Hours H 
                            WHERE H.proj_hours = '$nproj_hours' )
                            WHERE S.summary_id = '$summary_id'" 
                            or die ("couldn't update".mysql_error());

//multiple queries to get the field edited - i know this can be done more efficiently and safely, but I'm not proficient enough                         
        $query1 = mysql_query($sql1);
        if ($query1)
{
echo "success_1!";
}
else
            {
        die('error inserting new record_1'.mysql_error());
    } // end of the nested if statement

}

 if (isset($_POST['btnnew']))  

    {
    //echo "<pre>Value of \$_POST:</br>";print_r($_POST);echo"</pre>";

        $nclarity_id    = $_POST['nclarity_id'];
        $nproj_hours    = $_POST['nproj_hours'];
        $ndept_name     = $_POST['ndept_name'];
        $proj_id        = $_POST['nclarity_id'];
        $hours_id       = $_POST['nproj_hours'];
        $dept_id        = $_POST['ndept_name'];

        $sql        = "INSERT INTO `summary` VALUES (null,'$proj_id','$hours_id','$dept_id',NOW(),null)" 
                            or die ("couldn't update".mysql_error());
        $query = mysql_query($sql);

        if ($query)
{
echo "success_2!";
}
else
            {
        die('error inserting new record_2'.mysql_error());
    } // end of the nested if statement
}

    $res = mysql_query("SELECT *
                    FROM summary S
                    JOIN projects P ON S.proj_id = P.proj_id
                    JOIN departments D ON D.dept_id = S.dept_id
                    JOIN hours H ON H.hours_id = S.hours_id
                    WHERE P.proj_status = 'open'
                    ORDER BY D.dept_id
                                        LIMIT 0 , 30"); 

?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
   <tr>
   <td>
   <table width="100%" border="0" cellspacing="1" cellpadding="0">
   <tr>
   <td>&nbsp;</td>
   <td colspan="3"><strong>Update data in mysql</strong> </td>
   </tr>
   <tr>
   <td align="center">&nbsp;</td>
   <td align="center">&nbsp;</td>
   <td align="center">&nbsp;</td>
   </tr>
   <tr>
   <td align="center">&nbsp;</td>
   <td align="center"><strong>Clarity ID</strong></td>
   <td align="center"><strong>Hours</strong></td>
   <td align="center"><strong>Department</strong></td>
   </tr>
   </table>
   </td>
   </form>
   </tr>
   </table>

<table width="500" border="0" cellspacing="1" cellpadding="0">

<form method="post" action="index.php">
<tr>
<td>&nbsp;</td>

<select name="nclarity_id">
<option name="">
<?php
$sql = "SELECT proj_id, clarity_id FROM projects WHERE proj_status='open'";

$rs = mysql_query($sql);

$id = -9999; // a value that cannot exist in your database
if(isset($_GET['proj_id'])) { // check if there is an id in the $_GET variable
    $id = $_GET['proj_id']; // if so, set the $id variable
}
while($row = mysql_fetch_array($rs))
{
    $selectedText = "";
    if($row['proj_id'] == $id) { // if this row id is the same as the post id
        $selectedText = ' selected="selected"'; // set some text to be included in the markup
    }
    echo "<option value=\"".$row['proj_id']."\"".$selectedText.">".$row['clarity_id']."</option>\n  ";
}
?>
</select>

<select name="nproj_hours">
<option name="">
<?php
$sql = "SELECT hours_id, proj_hours FROM hours";
$rs = mysql_query($sql);
$id = -9999; // a value that cannot exist in your database
if(isset($_GET['hours_id'])) { // check if there is an id in the $_GET variable
    $id = $_GET['hours_id']; // if so, set the $id variable
}
while($row = mysql_fetch_array($rs))
{
    $selectedText = "";
    if($row['hours_id'] == $id) { // if this row id is the same as the post id
        $selectedText = ' selected="selected"'; // set some text to be included in the markup
    }
    echo "<option value=\"".$row['hours_id']."\"".$selectedText.">".$row['proj_hours']."</option>\n  ";

}
?>
</select>
<select name="ndept_name">
<option name="">
<?php
$sql = "SELECT dept_id, dept_name FROM departments";
$rs = mysql_query($sql);
$id = -9999; // a value that cannot exist in your database
if(isset($_GET['dept_id'])) { // check if there is an id in the $_GET variable
    $id = $_GET['dept_id']; // if so, set the $id variable
}
while($row = mysql_fetch_array($rs))
{
    $selectedText = "";
    if($row['hours_id'] == $id) { // if this row id is the same as the post id
        $selectedText = ' selected="selected"'; // set some text to be included in the markup
    }
    echo "<option value=\"".$row['dept_id']."\"".$selectedText.">".$row['dept_name']."</option>\n  ";

}
?>
</select>
<td align="center">
<input type="submit" name="btnnew" value="Enter New Record">
<input type="submit" name="btnsubmit" value="Save Edited Record">
</td>
</tr>
</form>
</table>

<table width="700" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="700" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="5"><strong>Project Information </strong> </td>
</tr>

<tr>
<tr>
<td align="center"><strong>Clarity ID</strong></td>
<td align="center"><strong>Estimated Hours</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Date Submitted</strong></td>
<td align="center"><strong></strong></td>
</tr>

<?php
while($row=mysql_fetch_array($res))
{

?>

<tr>
<td align="center"><?php echo $row['clarity_id']; ?></td>
<td align="center"><?php echo $row['proj_hours']; ?></td>
<td align="center"><?php echo $row['dept_name']; ?></td>
<td align="center"><?php echo $row['date_entered']; ?></td>
<td align="center"><a href="index.php?id=<?php echo $row['summary_id']; ?>">Edit</a></td>
</tr>

<?php
}

?>

</table>
</td>
</tr>
</table>


<?php
mysql_close();
?>
  • 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-06-12T15:04:32+00:00Added an answer on June 12, 2026 at 3:04 pm

    You can build the same options list, but check to see if the id is the same as the id you find in the $_POST or $_GET array.

    EDIT: just realised that you speicifed $_GET – substitute $_POST with $_GET in the example below.

    Something like:

    $id = -9999; // a value that cannot exist in your database
    if(isset($_POST['proj_id'])) { // check if there is an id in the $_POST variable
        $id = $_POST['proj_id']; // if so, set the $id variable
    }
    while($row = mysql_fetch_array($rs))
    {
        $selectedText = "";
        if($row['proj_id'] == $id) { // if this row id is the same as the post id
            $selectedText = ' selected="selected"'; // set some text to be included in the markup
        }
        echo "<option value=\"".$row['proj_id']."\"".$selectedText.">".$row['clarity_id']."</option>\n  ";
    
    }
    

    Hope this helps.

    EDIT to answer comment:

    Hi Mike, I’ve checked your code again, there’s a bit of confusion with the $_POST and $_GET variables. You find the $_POST variables from your form when it is submitted. The $_GET variables are from the URL. When you click the “edit” link, you are redirecting to index.php, and you are passing a single variable, called “id”. At this point, your $_GET array will contain a single key/value pair, called “id” and its value. Yet, I notice in your code you are trying to get a variable called ‘summary_id’ from the $_GET array, which probably doesn’t exist. Also, before you construct each options list, you are looking for $_GET['proj_id'], $_GET['hours_id'] and $_GET['dept_id'], which again don’t exist. In summary, on the “edit” page, you are searching for variables which you haven’t passed in the URL. This is probably why your dropdown lists are not being populated. One solution would be to change your “edit” link so that you pass also the proj_id, dept_id and hours_id variables. Also, bear in mind that the $_POST array is only populated when the form is submitted, and is only available to the page specified in the “action” attribute of the form element. As soon as you navigate away from that page (even if you navigate to the same page, as you are doing with your “edit” link), the $_POST array is no longer populated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 different select boxes (to select one option from drop down). All
I have a page on my site which has multiple drop down boxes as
I have few drop-down boxes. Is there any way to detect which dropdown was
I have some drop-down boxes that act as filters on a page. When either
I have two drop down boxes in my program. When you select an item
In my application i have two drop down boxes first box had origin second
how to fill text boxes based on drop down selection i have a table:
I have a form with two text boxes, one select drop down and one
I have one drop down list in my page, which contains two options. What
I have a drop down menu which you can see here on jsfiddle .

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.