I got a practise script going, I need to promote and demote users in database by changing their rank.
Here is what I have now !
Here is view.php:
<?php
include 'db.php';
mysql_connect($host,$user,$pass);
@mysql_select_db($db);
$result = mysql_query("SELECT username,rank FROM users");
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
echo '<table><tr><td><b>Username:</b><td><b>Rank:</b>';
while ($row = mysql_fetch_assoc($result)) {
echo '<tr><td><b>'.$row["username"].'</b>';
echo '<td>'.$row["rank"].'</a>';
if ($row["rank"] = 'Hermit')
echo '<a href="demote.php?username='.$row["username"].'">Demote</a>';
else
echo '<a href="promote.php?username='.$row["username"].'">Promote</a>';
}
echo '</table>';
mysql_close();
?>
Here is promote.php:
<?
mysql_query("UPDATE users SET rank = 'Outsider' WHERE rank = 'Hermit' AND username = '".$_GET['username']."'");
header ("location: view.php");
?>
and here is demote.php:
<?
mysql_query("UPDATE users SET rank = 'Hermit' WHERE rank = 'Outsider' AND username = '".$_GET['username']."'");
header ("location: view.php");
?>