Code: Select all
<?php
//MySQL connection
mysql_connect("dbhost", "dbuser", "dbpass") or die(mysql_error());
//Database connection
mysql_select_db("dbtable") or die(mysql_error());
$result = mysql_query("SELECT Name,Gender,birthday,secretquestion,secretanswer,Level FROM user WHERE Level='Member'") or die(mysql_error());
$tsv = array();
$html = array();
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
$htmm = "<br />" . implode("</td><td>", $row) ."<br />";
}
$tsv = implode("\r\n", $tsv);
$html = '<table border="1" width="100%"><tr><td bgcolor="#FFCC00">Name</td><td bgcolor="#FFCC00">Gender</td><td bgcolor="#FFCC00">Birthday</td><td bgcolor="#FFCC00">Secret Question</td><td bgcolor="#FFCC00">Secret Answer</td><td bgcolor="#FFCC00">Level</td></tr>' . implode("\r\n", $html) . '<br /></table>';
//echo $tsv;
echo $html;
echo '<table><tr><td>'. $row .'</td></tr></table>';
?>
<table width="100%" height="200px"><tr><td width="50%" valign="top">
<a href="?action=remove">Remove</a><br />
<a href="?action=ban">Ban</a><br />
<a href="?action=tban">Temporary Ban</a><br />
</td>
<td width="50%" valign="top">
<?php
//Removing a user
if($_GET['action'] == "remove") {
$click = true;
?>
<form action="testing.php?action=remove&remove-user" method="post">
<label for="name">Remove user:</label><br />
<input type="text" name="name" id="name" /><br />
<input type="submit" name="submit" value="submit" /> <input type="reset" name="reset" value="reset" />
</form>
<?php
$name = $_post['name'];
if(!empty($_POST['submit']))
{
mysql_query("SELECT Name FROM user WHERE Level='Member'");
mysql_query("DELETE FROM `user` WHERE Name = '$name'");
?>
The user was removed from the database.<br />
<?php
}
?>
<?php
}
//Banning a user
if($_GET['action'] == "ban") {
$click = true;
?>
<form action="testing.php?action=ban&ban-user" method="post">
<label for="uname">Ban user:</label><br />
<input type="text" name="uname" id="uname" /><br />
<input type="submit" name="submit2" value="submit" /> <input type="reset" name="reset" value="reset" />
</form>
<?php
$name = $_post['name'];
if(!empty($_POST['submit2']))
{
mysql_query("SELECT Name FROM user WHERE Level='Member'");
?>
The user was banned.<br />
<?php
}
?>
<?php
}
//Temporary Banning a user
if($_GET['action'] == "tban") {
$click = true;
?>
<form action="testing.php?action=tban&temp-ban" method="post">
<label for="bname">User to ban:</label><br />
<input type="text" name="bname" id="bname" /><br />
<label for="num">Number of days banned:</label><br />
<input type="text" name="num" id="num" /><br />
<input type="submit" name="submit3" value="submit" /> <input type="reset" name="reset" value="reset" />
</form>
<?php
$num = $_POST['num'];
if(!empty($_POST['submit3']))
{
echo 'The user was banned from the site for '. $num .' day(s).<br />';
}
}
if($click === true) {
echo '<p><a href="testing.php">Restart</a></p>';
}
?>
</td></tr></table>
<?php
//MySQL log off
mysql_close();
?>Let me explain what I want right now...
The field "Level" in the database is to determine a user which is Admin, Member, or Banned. If the user is banned than the Level would be "Banned" and if the user is an Admin than the Level would be "Admin"... on and on and on...
I want it only to show users who's level is a "Member" and it does that... that's correct... What I can't accomplish is changing the Level to Ban... for banning them...
I also can't accomplish the task in which I need to completely remove them from the database... I need help with that...
I also can't think of a way of temporarily banning a user... I know I have to set some timestamp or something but how to implement that and how to make the codes associate with each other and change the "Level" automatically once some time (in days) is expired... I don't know how... I need some help in that as well.