通过复选框插入

发布于 2024-09-30 10:25:49 字数 2216 浏览 0 评论 0原文

我创建了一个页面来显示与特定经理相关或低于特定经理的所有用户。如果用户已经注册,他的帐户将被停用,直到相关人员激活该帐户为止。我已经显示了所有用户和一个是否停用或激活的复选框。提交时,插入命令不起作用,数据库中没有任何更改。我有隐藏的用户 ID,但无法应用它。你能帮我吗

<?php

//get userid from login session

        $memberid = $_SESSION['SESS_MEMBER_ID'];

    //display all users concerning the user(login) is leader
        $sql = mysql_query("SELECT * FROM user WHERE userid in (SELECT userid FROM dept_user WHERE lead_id = '$memberid')");

       //display results in table
        print '<table border=1>';

print '<tr><td>Activate</td><td>First Name</td><td>Last Name</td><td>Email</td>td>Activate</td>';

print '<form method="GET" action="'.$PHP_SELF.'">';

$count = 0;

  while($res = mysql_fetch_array($sql)){

 $activate = $res['activate'];

 $checked = '';

$user = $res['userid'];

  if ($activate=='1'){

$checked = 'checked';

        }

 print '<tr><td><input type="checkbox" value="'.$user.'" name="activate[]" '.$checked.'></td>';

 print '<td>'.$res['firstname'].'</td>';

 print '<td>'.$res['lastname'].'</td>';

  print '<td>'.$res['email'].'</td>';

  print '<td>'.$res['activate'].'</td></tr>';

  print '<input type="hidden" name="userid" value="'.$user.'">';

   $count++;

  }

  print '</table>';


print '<br />With selected do:<br />';

print '<select name="useridselect">';

print '<option value="Select">Select</option>';

print '<option value="1">Activate</option>';

print '<option value="0">Desactivate</option>';

print '</select>';

print '<br /><input type="submit" value="Submit" name="submit">';

print '</form>';

    $useridselect = $_GET['useridselect'];

if(isset($_GET['submit'])){

foreach($_GET['activate'] as $value){

print_r($value);

$update=mysql_query("UPDATE user SET activate='$useridselect' WHERE userid='$user'");
        }

for($i=0;$i<$count;$i++){

$sql1="UPDATE user SET activate='$useridselect' WHERE userid='$user'";

$result1=mysql_query($sql1);

}

}   else{

echo 'No actions yet performed';

}

?>

I've created a page to display all users concerning or below a specific manager. If a user has registered, his account will be deactivated until the person concern activate it. i've displayed all the users and a checkbox whether to deactivate or activate. on submiting, the insert command is not working and nothing is being altered in the database. i've got the userid which is hidden but cant apply it. can you help me please

<?php

//get userid from login session

        $memberid = $_SESSION['SESS_MEMBER_ID'];

    //display all users concerning the user(login) is leader
        $sql = mysql_query("SELECT * FROM user WHERE userid in (SELECT userid FROM dept_user WHERE lead_id = '$memberid')");

       //display results in table
        print '<table border=1>';

print '<tr><td>Activate</td><td>First Name</td><td>Last Name</td><td>Email</td>td>Activate</td>';

print '<form method="GET" action="'.$PHP_SELF.'">';

$count = 0;

  while($res = mysql_fetch_array($sql)){

 $activate = $res['activate'];

 $checked = '';

$user = $res['userid'];

  if ($activate=='1'){

$checked = 'checked';

        }

 print '<tr><td><input type="checkbox" value="'.$user.'" name="activate[]" '.$checked.'></td>';

 print '<td>'.$res['firstname'].'</td>';

 print '<td>'.$res['lastname'].'</td>';

  print '<td>'.$res['email'].'</td>';

  print '<td>'.$res['activate'].'</td></tr>';

  print '<input type="hidden" name="userid" value="'.$user.'">';

   $count++;

  }

  print '</table>';


print '<br />With selected do:<br />';

print '<select name="useridselect">';

print '<option value="Select">Select</option>';

print '<option value="1">Activate</option>';

print '<option value="0">Desactivate</option>';

print '</select>';

print '<br /><input type="submit" value="Submit" name="submit">';

print '</form>';

    $useridselect = $_GET['useridselect'];

if(isset($_GET['submit'])){

foreach($_GET['activate'] as $value){

print_r($value);

$update=mysql_query("UPDATE user SET activate='$useridselect' WHERE userid='$user'");
        }

for($i=0;$i<$count;$i++){

$sql1="UPDATE user SET activate='$useridselect' WHERE userid='$user'";

$result1=mysql_query($sql1);

}

}   else{

echo 'No actions yet performed';

}

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人如玉 2024-10-07 10:25:49

我认为您的更新查询失败,因为您没有分配复选框值:

foreach($_GET['activate'] as $value){

print_r($value);
//Here instead of userid='$user' should be userid='$value'
$update=mysql_query("UPDATE user SET activate='$useridselect' WHERE userid='$value'");
}

我不明白下面代码的目的。

for($i=0;$i<$count;$i++){

$sql1="UPDATE user SET activate='$useridselect' WHERE userid='$user'";

$result1=mysql_query($sql1);

}

注意:请确保至少选中一个复选框。

I think your update query is getting failed as you are not assigning checkbox value:

foreach($_GET['activate'] as $value){

print_r($value);
//Here instead of userid='$user' should be userid='$value'
$update=mysql_query("UPDATE user SET activate='$useridselect' WHERE userid='$value'");
}

I don't understand the purpose of the code below.

for($i=0;$i<$count;$i++){

$sql1="UPDATE user SET activate='$useridselect' WHERE userid='$user'";

$result1=mysql_query($sql1);

}

Note: Please make sure that at least one of the checkbox is checked.

各空 2024-10-07 10:25:49

将 GET 方法更改为 POST 方法,以便隐藏值也会被 POSTED 到脚本中。此外,分离数据库逻辑也比一遍又一遍地引用相同的脚本更容易。

Change your GET method to a POST method, so the hidden values get POSTED as well to the script. Also, it's easier to seperate your DB logic instead of referring the same script over and over again.

情定在深秋 2024-10-07 10:25:49

您也可以遵循相同的删除逻辑。使用值为 userid 的复选框数组

You can follow the same logic for delete too. Use a checkbox array with value of userid

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文