我根据管理员输入创建了激活/停用。 这个想法是允许管理员查看帐户表中的所有帐户,并使用无线电输入从选择(激活或停用)中选择一个。 如果你们能在这个页面上帮助我,我真的很感激,我的项目差不多完成了。 谢谢大家的建议,我只是想让管理员使用此代码激活或停用用户帐户。 该代码基本上查看了帐户的所有信息,并且管理员只需复选任何她想激活的人并从无线电中选择(激活/取消激活),并根据她的输入将数据库中的值设置为0,即停用和1激活 。 谢谢
<?php
session_start();
if( isset($_SESSION['username']) ){
//Connect to DB
//include_once("Project/CIEconn.php");
$mysqlCON= mysqli_connect("localhost", "root", "","CIE") or die(mysqli_connect_error());
mysqli_select_db($mysqlCON,'CIE') or die ("no database");
if( isset($_POST['ActivateUsers']) ){
if( empty($_POST['Id']) || $_POST['Id'] == 0 ){
echo"<h4> please choose someone to activate </h4>";
}else{
$impid = implode("' , '" , $_POST['Id']);
$sqlDelete = "UPDATE Accounts SET Activated='$_POST[activate]' WHERE Id IN ('" . $impid . "')";
$DeleteQuery = mysqli_query($mysqlCON,$sqlDelete) or die ("Error : ".mysqli_error($mysqlCON));
}
}
$sqlCommand = "SELECT * FROM Accounts ";
$result = mysqli_query($mysqlCON,$sqlCommand) or die(mysql_error());
echo "<h1> Activate / Deactive User Account </h1>";
echo "<table border='1' width = 80% align=center >
<tr>
<th>Check </th>
<th>SSU ID</th>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>User Type </th>
<th>Activated</th>
<th>Activate/Deactive</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<form action='ActivateD.php' method='post'>";
echo "<td> <input type='checkbox' name='Id[]' value='". $row['SSU'] ."' /> </td> " ;
echo "<td align=center > " . $row['SSU'] . "</td>";
echo "<td align=center>" . $row['Email'] . "</td>";
echo "<td align=center>" . $row['First_Name'] . "</td>";
echo "<td align=center>" . $row['Last_Name'] . "</td>";
echo "<td align=center>" . $row['userType'] . "</td>";
echo "<td align=center>" . $row['Activated'] . "</td>";
echo "<td align=center>" .
"
<input type='radio' name='activate' value='1' > Activate
<input type='radio' name='activate' value='0'> Deactive
</form>"
. "</td>";
echo "</tr> ";
}
echo "</table>";
echo " <br>
<form action='ActivateD.php' method='post'>
<div align='center'>
<input type='submit' name='ActivateUsers' value='Activate/Deactive'>
</div>
</form>";
mysqli_close($mysqlCON);
}
else{echo "must logout to see this page..!!";}
?>
<html>
<head><title> Activate / Deactive User Account </title>
<style type="text/css">
body{
background-color: #23438e;
}
table{
background: white;
}
h1{
color: #FF942B;
text-align: center;
padding-top : 50px;
text-decoration: none;
}
</style>
</head>
<body>
</body>
</html>
答案 0 :(得分:0)
您的脚本似乎存在一些问题:
$sqlDelete = "UPDATE Accounts SET Activated='$_POST[activate]' WHERE Id IN ('" . $impid . "')";
您应该使用$sql = "update Accounts set Activated='" . $_POST['activate'] . "' where Id in ('" . $impid . "')";