Forum Moderators: coopster
please help me about my headache problem. The function I want to create is shown as below:
Account Hr Marketing CS CEO IT Operation
--------¦----------¦------¦----------¦----¦-----¦------¦----------¦
Name 1 checkbox checkbox checkbox checkbox checkbox checkbox
Name 2 checkbox checkbox checkbox checkbox checkbox checkbox
Name 3 checkbox checkbox checkbox checkbox checkbox checkbox
Name 4 checkbox checkbox checkbox checkbox checkbox checkbox
Name 5 checkbox checkbox checkbox checkbox checkbox checkbox
Name 6 checkbox checkbox checkbox checkbox checkbox checkbox
This table will allow those users to enter only with "checked" category.
I am suffering with the update query. For example, Name 1 will checked with 'Account'&'Marketing' and Name 2 will checked with 'CS'&'IT'
I think I am confusing with the logic. Below are my code, please have a look and correct my error.
if($_POST[submit])
{
$userid=$_POST[userid];
$per=$_POST[permission];
foreach($userid as $user)
{
$y=$user;
foreach($per as $per1)
{
$z=$per1;
}
$u1="UPDATE `menu_p` SET `account`='$z', `hr`='$z',`marketing`='$z',`cs`='$z',`ceo`='$z',`it`='$z',`operation`='$z' WHERE `userid`='$y'";
$u=mysql_query($u1)or die (mysql_error());
}
}
print "<form method=\"POST\" action=\"\">";
print "<div class=\"permission\">";
print "<div class=\"permission_title\"><h2>User Permission</h2></div>";
print "<div class=\"permission_dept\"><div class=\"permission_dept1\" style=\"border:0;width:102px;\"> </div><div class=\"permission_dept1\">Account</div><div class=\"permission_dept1\">HR</div><div class=\"permission_dept1\">Marketing</div><div class=\"permission_dept1\">CS</div><div class=\"permission_dept1\">CEO</div><div class=\"permission_dept1\">IT</div><div class=\"permission_dept1\">Operation</div></div>";
$sql=mysql_query("SELECT * FROM `menu_p`")or die (mysql_error());
while ($p=mysql_fetch_assoc($sql))
{
$name=strtoupper($p[userid]);
if ($p[account] == 1)
{
$p1="<input type=\"checkbox\" name=\"permission[]\" value=\"1\" checked=\"checked\">";
}
else
{
$p1="<input type=\"checkbox\" name=\"permission[]\" value=\"0\">";
}
if ($p
I would like to say thank you to those who helping me on this issue. Thanks a lot...
Then it becomes just one simple UPDATE loop like:
foreach ($_POST['userid'] as $user)
{
mysql_query("UPDATE `menu_p` SET `account` = {$_POST['account'][$user]}, `marketing` = {$_POST['marketing'][$user]},.......... WHERE `userid`='$user'");
}