Need help with admin page...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bogey
Forum Commoner
Posts: 34
Joined: Sat Nov 10, 2007 5:51 pm

Need help with admin page...

Post by Bogey »

I'm also working on an admin page right now... the following is what I currently have...

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();
?>
I hope that the code itself is pretty self-explanatory...

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.
Bogey
Forum Commoner
Posts: 34
Joined: Sat Nov 10, 2007 5:51 pm

Post by Bogey »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I notice that the script doesn't delete or change the level because there's a variable there... other than that... it works... (if I put the thing I want to remove by my self in the source code and that is not helpful... no not at all). Here is the code as I have it right now.

Code: Select all

<body bgcolor="#000000">
<table width="100%" bgcolor="#666666"><tr><td>
<?php
$click = false;
//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 bgcolor=\"#EEEEEE\">" .implode("</td><td bgcolor=\"#FFFFFF\">", $row) .              "</td></tr>";
   $htmm = "<br />" . implode("</td><td>", $row) ."<br />";
}

$tsv = implode("\r\n", $tsv);
$html = '<div style="overflow: auto; height: 500px;"><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></div>';



//echo $tsv;
echo $html;

echo '<table><tr><td>'. $row .'</td></tr></table>';
?>

<table width="100%" height="200px"><tr><td width="15%" valign="top" bgcolor="#CECECE">
<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="85%" valign="top" bgcolor="FFCC00">
<?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("DELETE FROM user WHERE name=". $name);
?>
The user was removed from the database.<br />
<p><a href="testing.php">Refresh</a></p>
<?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
  $uname = $_post['name'];
  if(!empty($_POST['submit2']))
  {
  mysql_query(" UPDATE user SET Level = 'Ban' WHERE Name = ". $uname);

?>
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
  $bname = $_POST['bname'];
  $num = $_POST['num'];

  if(!empty($_POST['submit3']))
  {
   echo $bname .' was banned from the site for '. $num .' day(s).<br />';
  }
}
if($click === false) {
 echo 'Click on the menu to the left to complete an action.';
}
?>
</td></tr></table>
<?php

//MySQL log off
mysql_close();
?>
</td></tr></table>
</body>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply