通过复选框插入
我创建了一个页面来显示与特定经理相关或低于特定经理的所有用户。如果用户已经注册,他的帐户将被停用,直到相关人员激活该帐户为止。我已经显示了所有用户和一个是否停用或激活的复选框。提交时,插入命令不起作用,数据库中没有任何更改。我有隐藏的用户 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您的更新查询失败,因为您没有分配复选框值:
我不明白下面代码的目的。
注意:请确保至少选中一个复选框。
I think your update query is getting failed as you are not assigning checkbox value:
I don't understand the purpose of the code below.
Note: Please make sure that at least one of the checkbox is checked.
将 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.
您也可以遵循相同的删除逻辑。使用值为 userid 的复选框数组
You can follow the same logic for delete too. Use a checkbox array with value of userid