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 6623759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:34:13+00:00 2026-05-25T21:34:13+00:00

I have two php pages, admin_bkp.php and db_submit.php . The admin_bkp.php gives a user

  • 0

I have two php pages, admin_bkp.php and db_submit.php.

The admin_bkp.php gives a user a table that let’s the user set permissions to employees and save the permissions to a MySQL table called rights. The employee info is gathered from hs_hr_employee and saved to rights together with an extra ‘Permissions’ column.

It was working at first, you could save the data and when you refresh the page, the admin_bkp.php shows you the default value in the comboboxes as you had previously chosen.

However, now it is returning the default value as ‘All’ which is something I don’t want. I want it to show the chosen value from before.

The admin_php.bkp saves the values upon clicking the ‘Save’ button

This is the code:
admin_bkp.php

 <?php

$connection = mysql_connect('localhost','admin','root');

if( isset($_POST['submit']) )
{
    if( isset( $_POST['cb_change'] ) && is_array( $_POST['cb_change'] ))
    {
        foreach( $_POST['cb_change']  as $emp_number => $permission)
        {       
echo "$permission";
            $sql = "UPDATE `rights` SET Permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
            echo __LINE__.": sql: {$sql}\n";
            mysql_query( $sql );
        }
    }
}
?>
<p style="text-align: center;">
    <span style="font-size:36px;"><strong><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 128, 128);">File Database - Administration Panel</span></span></strong></span></p>
<p style="text-align: center;">
    &nbsp;</p>

<head>
<style type="text/css">
/*
http://icant.co.uk/csstablegallery/index.php?css=71

Data Tables and Cascading Style Sheets Gallery
Title: Casablanca
Author: RODrigo CASTilho Galv?o Ferreira - RODCAST
URL: http://www.rodcast.com.br
Update: 04/04/2008 10:51 AM
*/
body{
background: url('bg.gif');
}
table {
    color: #666;
    font: 0.8em/1.6em "Trebuchet MS",Verdana,sans-serif;
    border-collapse: collapse;
    background: #fff;
}

table,caption {
    margin: 0 auto;
    border-right: 0px solid #CCC;
    border-left: 0px solid #CCC;    

}

caption,th,td {
    border-left: 0;
    padding: 10px;

}

caption,thead th,tfoot th,tfoot td {
    background-color: #216dab;
    color: #FFF;
    font-weight: bold;
    text-transform: uppercase
}

thead th {
    background-color: #666;
    color: #fff;
    text-align: center
}

tbody th {
    padding: 20px 10px
}

tbody tr.odd {
    background-color: #F7F7F7;
    color: #666;

}

tbody a {
    padding: 1px 2px;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px dotted #E63C1E;
    background: #7bafd9;
}

tbody a:active,tbody a:hover,tbody a:focus,tbody a:visited {
    color: #fff;

}

tbody tr:hover {
    background-color: #EEE;
    color: #333
}

tbody tr:hover a {
    /*background-color: #FFF*/
    color:fff;
}

tbody td+td+td+td a {
    color: #fff;
    font-weight: bold;
    border-bottom: 0;

}

tbody td+td+td+td a:active,tbody td+td+td+td a:hover,tbody td+td+td+td a:focus,tbody td+td+td+td a:visited {
    color: #fff
}

tbody td a[href="http://www.rodcast.com.br/"] {
    margin: 0 auto;
    display: block;
    width: 15px;
    height: 15px;
    background: transparent url('data:image/gif;base64,R0lGODlhDwAPAIAAACEpMf///yH5BAAAAAAALAAAAAAPAA8AAAIjjA8Qer0JmYvULUOlxXEjaEndliUeA56c97TqSD5pfJnhNxYAOw%3D%3D') no-repeat;
    text-indent: -999em;
    border-bottom: 0;

}

tbody a:visited:after {
    font-family: Verdana,sans-serif;
    content: "\00A0\221A"
}
</style>
</head>

    <form method="post" action="db_submit.php">

    <?php 


        if (!$connection)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db('users', $connection);

        #mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');


        $result = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, Permissions FROM rights");

        mysql_query("INSERT INTO rights (emp_number, employee_id, emp_firstname, emp_lastname)
                    SELECT emp_number, employee_id, emp_firstname, emp_lastname
                    FROM hs_hr_employee
                    ON DUPLICATE KEY UPDATE employee_id = VALUES(employee_id), emp_number = VALUES(emp_number)
                    ");

        $duplicates = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, count(*) FROM rights GROUP BY emp_number, employee_id, emp_firstname, emp_lastname having count(*) > 1");

        $count = mysql_num_rows($duplicates);

        if ($count > 0) {
        while ($row = mysql_fetch_assoc($duplicates)) {
        $field = $row["emp_number"];
        $limit = $row["count(*)"] - 1;
        mysql_query("DELETE FROM rights WHERE emp_number='$field' LIMIT $limit");
        }
        mysql_free_result($duplicates);
        }           


        echo "<center>";
        /*
        echo "      
        <table >
        <tr>
        <th>Employee Number</th>
        <th>ID</th>
        <th>Name</th>
        <th>Surname</th>
        <th>Permissions</th>
        <th>Change</th>
        </tr>"; */

        echo "      
        <table >
        <tr>
        <th>Employee Number</th>
        <th>ID</th>
        <th>Name</th>
        <th>Surname</th>        
        <th>Permissions</th>
        </tr>";

        while($row = mysql_fetch_array($result))
          {
          echo "<tr>";
          echo "<td>" . $row['emp_number'] . "</td>";
          echo "<td>" . $row['employee_id'] . "</td>";
          echo "<td>" . $row['emp_firstname'] . "</td>";
          echo "<td>" . $row['emp_lastname'] . "</td>";
          #echo "<td>" . $row['Permissions'] . "</td>";



          echo "<td>
                      <select>
                         <option value='All'>All</option> 
                         <option value='Remote Gaming' selected='selected'>Remote Gaming</option> 
                         <option value='Landbased Gaming'>Landbased Gaming</option>
                         <option value='General Gaming'>General Gaming</option>
                      </select>
                    </td>
                    "; 
          echo "</tr>" ;
          echo "<input type='hidden' name='emp_id[]' value='". $row['employee_id'] ."'>";
          }


        $selected = $row['Permissions'];
            $options = array(
              "Remote Gaming",
              "Landbased Gaming",
              "General Gaming"
            );


            foreach ($options as $option){
              if($option == $selected){
                echo "<option value='$option' selected='selected'>$option</option>";
              }else{
                echo "<option value='$option'>$option</option>";
              }
            }
          #echo "<td>" . $row['Change'] . "</td>";

          echo "</table>
                    <p style='text-align: right;'>
                        <input name='Save_Btn' type='Submit' value='Save' />
                    </p>

                </center>";

     mysql_close($connection);

    ?>

<p style="text-align: center;">
    &nbsp;</p>
<p style="text-align: center;">
    &nbsp;</p>

</form>

db_submit.php:

<html>
<body>
<p>Data submitted successfully.</p>

<?php

$connection = mysql_connect('localhost','admin','root');
mysql_select_db('users', $connection);

$cbchange = $_POST['cb_change'];
$emp_id = $_POST['emp_id'];

foreach($cbchange as $a => $b){
    echo $cbchange[$a] ." - ". $emp_id[$a];
    echo "<br/>";

    $query = "

                UPDATE `rights`
                SET `rights`.`Permissions`='".$cbchange[$a]."'
                WHERE `rights`.`employee_id`='".$emp_id[$a]."'
                ";
    mysql_query($query);
}

?>
</body>
</html>

Here are some images to give you a general idea of the setup.

enter image description here
enter image description here

Original Code:

   <?php

$connection = mysql_connect('localhost','admin','root');

if( isset($_POST['submit']) )
{
    if( isset( $_POST['cb_change'] ) && is_array( $_POST['cb_change'] ))
    {
        foreach( $_POST['cb_change']  as $emp_number => $permission)
        {       
echo "$permission";
            $sql = "UPDATE `rights` SET Permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
            echo __LINE__.": sql: {$sql}\n";
            mysql_query( $sql );
        }
    }
}
?>
<p style="text-align: center;">
    <span style="font-size:36px;"><strong><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 128, 128);">File Database - Administration Panel</span></span></strong></span></p>
<p style="text-align: center;">
    &nbsp;</p>

<head>
<style type="text/css">
/*
http://icant.co.uk/csstablegallery/index.php?css=71

Data Tables and Cascading Style Sheets Gallery
Title: Casablanca
Author: RODrigo CASTilho Galv?o Ferreira - RODCAST
URL: http://www.rodcast.com.br
Update: 04/04/2008 10:51 AM
*/
body{
background: url('bg.gif');
}
table {
    color: #666;
    font: 0.8em/1.6em "Trebuchet MS",Verdana,sans-serif;
    border-collapse: collapse;
    background: #fff;
}

table,caption {
    margin: 0 auto;
    border-right: 0px solid #CCC;
    border-left: 0px solid #CCC;    

}

caption,th,td {
    border-left: 0;
    padding: 10px;

}

caption,thead th,tfoot th,tfoot td {
    background-color: #216dab;
    color: #FFF;
    font-weight: bold;
    text-transform: uppercase
}

thead th {
    background-color: #666;
    color: #fff;
    text-align: center
}

tbody th {
    padding: 20px 10px
}

tbody tr.odd {
    background-color: #F7F7F7;
    color: #666;

}

tbody a {
    padding: 1px 2px;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px dotted #E63C1E;
    background: #7bafd9;
}

tbody a:active,tbody a:hover,tbody a:focus,tbody a:visited {
    color: #fff;

}

tbody tr:hover {
    background-color: #EEE;
    color: #333
}

tbody tr:hover a {
    /*background-color: #FFF*/
    color:fff;
}

tbody td+td+td+td a {
    color: #fff;
    font-weight: bold;
    border-bottom: 0;

}

tbody td+td+td+td a:active,tbody td+td+td+td a:hover,tbody td+td+td+td a:focus,tbody td+td+td+td a:visited {
    color: #fff
}

tbody td a[href="http://www.rodcast.com.br/"] {
    margin: 0 auto;
    display: block;
    width: 15px;
    height: 15px;
    background: transparent url('data:image/gif;base64,R0lGODlhDwAPAIAAACEpMf///yH5BAAAAAAALAAAAAAPAA8AAAIjjA8Qer0JmYvULUOlxXEjaEndliUeA56c97TqSD5pfJnhNxYAOw%3D%3D') no-repeat;
    text-indent: -999em;
    border-bottom: 0;

}

tbody a:visited:after {
    font-family: Verdana,sans-serif;
    content: "\00A0\221A"
}
</style>
</head>

    <form method="post" action="db_submit.php">

    <?php 


        if (!$connection)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db('users', $connection);

        #mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');


        $result = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, Permissions FROM rights");

        mysql_query("INSERT INTO rights (emp_number, employee_id, emp_firstname, emp_lastname)
                    SELECT emp_number, employee_id, emp_firstname, emp_lastname
                    FROM hs_hr_employee
                    ON DUPLICATE KEY UPDATE employee_id = VALUES(employee_id), emp_number = VALUES(emp_number)
                    ");

        $duplicates = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, count(*) FROM rights GROUP BY emp_number, employee_id, emp_firstname, emp_lastname having count(*) > 1");

        $count = mysql_num_rows($duplicates);

        if ($count > 0) {
        while ($row = mysql_fetch_assoc($duplicates)) {
        $field = $row["emp_number"];
        $limit = $row["count(*)"] - 1;
        mysql_query("DELETE FROM rights WHERE emp_number='$field' LIMIT $limit");
        }
        mysql_free_result($duplicates);
        }           


        echo "<center>";
        /*
        echo "      
        <table >
        <tr>
        <th>Employee Number</th>
        <th>ID</th>
        <th>Name</th>
        <th>Surname</th>
        <th>Permissions</th>
        <th>Change</th>
        </tr>"; */

        echo "      
        <table >
        <tr>
        <th>Employee Number</th>
        <th>ID</th>
        <th>Name</th>
        <th>Surname</th>        
        <th>Permissions</th>
        </tr>";

        while($row = mysql_fetch_array($result))
          {
          echo "<tr>";
          echo "<td>" . $row['emp_number'] . "</td>";
          echo "<td>" . $row['employee_id'] . "</td>";
          echo "<td>" . $row['emp_firstname'] . "</td>";
          echo "<td>" . $row['emp_lastname'] . "</td>";
          #echo "<td>" . $row['Permissions'] . "</td>";

          echo "<td> <select name='cb_change[]' SELECTED VALUE=".$row['Permissions'].">
          <option value='All'>All</option> 
          <option value='Remote Gaming'>Remote Gaming</option> 
          <option value='Landbased Gaming'>Landbased Gaming</option>
          <option value='General Gaming'>General Gaming</option>
          </select> </td>"; 
          echo "</tr>" ;
          echo "<input type='hidden' name='emp_id[]' value='". $row['employee_id'] ."'>";
          }

          #echo "<td>" . $row['Change'] . "</td>";

          echo "</table>
                    <p style='text-align: right;'>
                        <input name='Save_Btn' type='Submit' value='Save' />
                    </p>

                </center>";

     mysql_close($connection);

    ?>

<p style="text-align: center;">
    &nbsp;</p>
<p style="text-align: center;">
    &nbsp;</p>

</form>

Can you kindly point me in the right direction?

  • 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-25T21:34:14+00:00Added an answer on May 25, 2026 at 9:34 pm

    If the correct values are displaying in the database, then your problem is with displaying the data at the other end. From what I understand, you want to output a list of permissions in an html select box, with the currently stored permission set as ‘selected’ for that user, correct?

    If so, your code here:

    echo "<td> <select name='cb_change[]' SELECTED VALUE=".$row['Permissions'].">
     <option value='All'>All</option> 
     <option value='Remote Gaming'>Remote Gaming</option> 
     <option value='Landbased Gaming'>Landbased Gaming</option>
     <option value='General Gaming'>General Gaming</option>
     </select></td>"; 
    

    Is wrong. you need to match the <option> value to the currently selected value, then stick attribute on it.

    eg:

    $selected = $row['Permissions'];
    $options = array(
      "Remote Gaming",
      "Landbased Gaming",
      "General Gaming"
    );
    foreach ($options as $option){
      if($option == $selected){
        echo "<option value='$option' selected='selected'>$option</option>";
      }else{
        echo "<option value='$option'>$option</option>";
      }
    }
    

    That should work.

    FINAL EDIT

    The following code marked ‘Code’ should be placed underneath:

    echo "      
        <table >
        <tr>
        <th>Employee Number</th>
        <th>ID</th>
        <th>Name</th>
        <th>Surname</th>        
        <th>Permissions</th>
        </tr>";
    

    Code:

        $options = array(
            "All",
            "Remote Gaming",
            "Landbased Gaming",
            "General Gaming"
        );
    
        while($row = mysql_fetch_array($result))
        {
            echo "<tr>";
            echo "<td>" . $row['emp_number'] . "</td>";
            echo "<td>" . $row['employee_id'] . "</td>";
            echo "<td>" . $row['emp_firstname'] . "</td>";
            echo "<td>" . $row['emp_lastname'] . "</td>";
            #echo "<td>" . $row['Permissions'] . "</td>";
            echo "<td> <select name='cb_change[]'>";
            foreach($options as $option){
                if($option == $row['Permissions']){
                    echo "<option value='" . $option . "' selected='selected'>". $option ."</option>";
                }else{
                    echo "<option value='" . $option . "'>". $option ."</option>";
                }
            }
            echo "</select> </td>";
            echo "</tr>" ;
            echo "<input type='hidden' name='emp_id[]' value='". $row['employee_id'] ."'>";
        } // end while
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two PHP files that I need to link. How can I link
I'm not sure if I'm asking this properly. I have two PHP pages located
I have two pages name one.php and two.php in one.php i have a combo
So I have two pages: index.php and contents.php . Index.php is doing an XMLHttpRequest
I have two tables, Pages and Posts that are in HABTM and are joined
I have two different PHP files that both write to the same file. Each
I have two pages apply.php and registration.php. In registration.php , i have if(isset($_POST['submitted'])){ //validation
lets say i have two pages links.html & contents.php ... first page contains only
I have two pages: categories.php in categories.php page I fetch all categories. news.php in
I have two pages redirection in my index.php. The pages are example_system_os.php and example_mobile_os.php

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.