I have an html page that gets data from 'hs_hr_employee' table and lays the info in a table on a web page. Then I have another table 'rights' which gets info from 4 columns from the 'hs_hr_employee' table and stores them in columns. In addition to those 4, the 'rights' table has an extra column 'Permissions'.

Now, I have a combobox with 4 options. When I click the 'Save' button I want to store the value select in the combobox and save it in the 'rights' table in relation to the user.

The ComboBoxes under the Permissions column will save to the 'rights' table upon clicking the 'Save' button.

(Each user has a combobox next to it).

A MySQL query should insert data from hs_hr_employee table into rights table as well as the selected value from the combobox. So the employee_id, employee_num, Firstname, Lastname and ComboBox values should be saved to the 'rights' table. The hs_hr_employee table is only used to gather data from it, and not to save to it. Everything is written in the rights table when the 'Save' button is clicked.

I'm finding trouble when trying to insert the combobox data into the 'rights' table when clicking the Save button.

echo "<td> <select name='cb_permissions['".$row['emp_number']."'><option value='all'>All</option> <option value='remote'>Remote Gaming</option> <option value='landbased'>Landbased Gaming</option> <option value='general'>General Gaming</option> </select> </td>";

This is the code so far:

<?php

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

if( isset($_POST['submit']) )
{
    if( isset( $_POST['cb_permissions'] ) && is_array( $_POST['cb_permissions'] ))
    {
        foreach( $_POST['cb_permissions']  as $emp_number => $permission)
        {
            $sql = "UPDATE `your_permission_table` 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">
table, td, th
{
border:1px solid #666;
font-style:Calibri;
}
th
{
background-color:#666;
color:white;
font-style:Calibri;
}
</style>
</head>

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

    <?php 

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

        mysql_select_db('users', $connection);

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

        echo "<center>";

        echo "<table >
        <tr>
        <th>Employee Number</th>
        <th>Employee ID</th>
        <th>Surname</th>
        <th>Name</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_lastname'] . "</td>";
          echo "<td>" . $row['emp_firstname'] . "</td>";
		  echo "<td> <select name='cb_permissions['".$row['emp_number']."'><option value='all'>All</option> <option value='remote'>Remote Gaming</option> <option value='landbased'>Landbased Gaming</option> <option value='general'>General Gaming</option> </select> </td>"; 
          echo "</tr>" ;

          }

        echo "</table>";

        echo "</center>";

		$_POST['cb_permissions'];
		
		echo mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');
	
	 mysql_close($connection);
       

    ?>

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

<p style="text-align: right;">
    <input name="Save_Btn" type="button" value="Save" />

	
	</p>
	
	
</form>

Any help would be aprpeciated.

Thanks,
Brian

thats a very confusing post. however, something in the select name doesnt look right.

<select name='cb_permissions['".$row['emp_number']."'>

Possibly an extra bracket at the start ...ions['".$row... maybe try this

<select name='cb_permissions'".$row['emp_number']."'>

ref:line71

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.