gpt4 book ai didi

PHP/HTML : activate users through admin page using radio button

转载 作者:行者123 更新时间:2023-11-29 21:35:38 26 4
gpt4 key购买 nike

我正在根据管理员输入创建激活/停用。这个想法是允许管理员查看帐户表中的所有帐户,并使用 radio 输入从选择(激活或停用)中选择一个帐户。如果你们能在这个页面上帮助我,我真的很感激,我的项目即将完成。谢谢大家的建议,我只是想让管理员可以选择使用此代码激活或停用用户帐户。该代码基本上查看帐户的所有信息,管理员只需选中她想要激活的任何人并从 radio 中选择(激活/停用),然后根据她的输入将数据库中的值设置为 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>

最佳答案

您的脚本似乎存在几个问题:

  1. 您将在每个单选输入和复选框周围包裹一个表单,但在提交按钮周围包裹一个单独的表单。在此设置中,表单在提交时不会发送正确的数据。
  2. 在每一行上复制具有相同名称的单选框。由于您仅使用单个值来表示事件/非事件,因此您应该在表单底部放置一组单选按钮。
  3. 您的 SQL 查询转义不正确:

而不是$sqlDelete = "UPDATE Accounts SET Activated='$_POST[activate]' WHERE Id IN ('". $impid . "')";

您应该使用 $sql = "update Accounts set Activated='"。 $_POST['激活'] 。 "' where Id in ('". $impid . "')";

  • 缺乏错误处理和输入清理
  • 关于PHP/HTML : activate users through admin page using radio button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34938683/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com