<?php
session_start(); //allow sessions.
include("config.php"); //get config
if($logged[username] && $logged[userlevel] ==6) // allows level 5 to view this page
if (!$_POST[update])
# If User Is Logged In
switch($_GET[badge])
{
# Lets Us Use One Page For Everything
default:
# The Default Page
echo("<b><u>Current Badges</u></b><br><br>");
$getbadges = mysql_query("SELECT * FROM badges");
while($badge = mysql_fetch_array($getbadges))
{
echo("Badge Name: $badge[name]<br>
Badge Description: $badge[desc]<br>
Badge: <img src=\"$badge[url]\"><br><br>
<a href=\"?badge=delete&id=$badge[id]\">Delete The $badge[name] Badge</a> - <a href=\"?badge=edit&id=$badge[id]\">Edit The $badge[name] Badge</a><br><br>");
}
echo("<br><b><u>More Options</u></b><br>");
echo("<a href=\"?badge=create\">Create A Badge</a><br>
<a href=\"?badge=give\">Give User A Badge</a><br>
<a href=\"?badge=deletebadge\">Take Badge away from member</a><br>");
# Options
break;
# End Default Page
case 'edit':
# Create A Badge Page
if ($_GET[id]) {
if(!$_POST[ed]) {
$getbadgeid = mysql_query("SELECT * FROM badges WHERE id = '$_GET[id]'");
$b = mysql_fetch_array($getbadgeid);
echo("<form method=\"POST\">
Badge Name: <input type=\"text\" value=\"$b[name]\" name=\"bname\"><br>
Image URL: <input type=\"text\" name=\"burl\" value=\"$b[url]\"><br>
Badge Description: <input type=\"text\" name=\"bdesc\" value=\"$b[desc]\"><br><br>
<input type=\"submit\" name=\"ed\" value=\"Update Badge\">
</form>");
# The Create A Badge Form
}else{
# The Form Has Been Submitted
$ub2 = mysql_query ("UPDATE `badges` SET `name` = '$_POST[bname]', `url` = '$_POST[burl]', `desc` = '$_POST[bdesc]' WHERE `badges`.`id` =$_GET[id]");
$ub3 = mysql_query ("UPDATE `ubadges` SET `bname` = '$_POST[bname]' WHERE `ubadges`.`bid` = $_GET[id]");
echo("Badge $_POST[bname] updated");
# Inserts New Badge
}
}
break;
# End Create Page
case 'create':
# Create A Badge Page
if(!$_POST[create]) {
echo("<form method=\"POST\">
Badge Name: <input type=\"text\" name=\"bname\"><br>
Image URL: <input type=\"text\" name=\"burl\" value=\"https://www.\"><br>
Badge Description: <input type=\"text\" name=\"bdesc\"><br><br>
<input type=\"submit\" name=\"create\" value=\"Create Badge\">
</form>");
# The Create A Badge Form
}else{
# The Form Has Been Submitted
$updatebadges = mysql_query("INSERT INTO badges (`name`, `url`, `desc`, ) VALUES ('$_POST[bname]','$_POST[burl]','$_POST[bdesc]')");
echo("A new badge has been set up!");
# Inserts New Badge
}
break;
case 'delete':
# Delete Page
$getbadgeid = mysql_query("SELECT * FROM badges WHERE id = '$_GET[id]'");
$c = mysql_fetch_array($getbadgeid);
# Get Badge ID
$deletebadge = mysql_query("DELETE FROM badges WHERE id = '$_GET[id]'");
echo("The $c[name] badge has been deleted!");
# Delete Badge
break;
# End Delete Page
case 'give':
# Give Page
$getbadges = mysql_query("SELECT * FROM badges");
$g = mysql_fetch_array($getbadges);
# Checks Table
if(!$_POST[apply]) {
echo("<form method=\"POST\">
Badge Name: <select name=\"bname\">");
$badges = mysql_query("SELECT * FROM badges");
while($b = mysql_fetch_array($badges))
{
echo("<option value=\"$b[name]\">$b[name]</option>");
}
echo("</select><br>Give To: <select name=\"give\">");
$users = mysql_query("SELECT * FROM members");
while($mem = mysql_fetch_array($users))
{
echo("<option value=\"$mem[username]\">$mem[username]</option>");
}
echo("</select><br><br><input type=\"submit\" name=\"apply\" value=\"Give Badge\">
</form>");
# The Give A User A Badge Form
}else
# The Form Has Been Submitted
{
$checkbadge = mysql_query("SELECT * FROM ubadges WHERE username = '$_POST[give]'");
$c = mysql_fetch_array($checkbadge);
# Checks Table
if($c[bname] == $_POST[bname]) {
echo("$_POST[give] already has the $_POST[bname] badge!");
# Checks To See If User
# Already Has The Badge
}else{
$badgeinfo = mysql_query("SELECT * FROM badges WHERE name = '$_POST[bname]'");
$d = mysql_fetch_array($badgeinfo);
$givebadge = mysql_query("INSERT INTO ubadges (`bname`, `username`,`bid`) VALUES ('$_POST[bname]', '$_POST[give]', '$d[id]')");
echo("$_POST[give] has received the $_POST[bname] badge!");
# Insert Badge
}
}
break;
# End Apply Badge Page
case 'deletebadge': //delete BADGE HELP
# Give Page
$getbadgeid2 = mysql_query("SELECT * FROM badges WHERE id = '$_GET[id]'");
$cb = mysql_fetch_array($getbadgeid2);
$name= $cb[bname];
# Checks Table
if(!$_POST[apply]) {
echo("<form method=\"POST\">
Badge Name: <select name=\"bname\">");
$badges = mysql_query("SELECT * FROM badges");
while($q = mysql_fetch_array($badges))
{
echo("<option value=\"$q[name]\">$q[name]</option>");
}
echo("</select><br>Take From:
<input type='text' name='useraway'>
<input type=\"submit\" name=\"apply\" value=\"Take Away Badge!\">
</form>");
# the badge form
}else{
$deletebadge = mysql_query("DELETE FROM ubadges WHERE username = '$_POST[useraway]' AND bname = '$_POST[bname]'");
echo("$_POST[useraway] no longer has the $_POST[bname] badge!");
# Insert Badge
}
break;
}
# End Apply Badge Page
?>
while($l = mysql_fetch_array($findbadges))
{
# Checks Table For Badges
$findinfo = mysql_query("SELECT * FROM badges");
while($p = mysql_fetch_array($findinfo))
{
# Checks Badges
if($l[bname] == $p[name]) {
echo("<img alt="$p[desc]" border="0" src="$p[url]"> ");
}
}
}
I don't think it needs any other code ^^
`id` int(11) NOT NULL auto_increment,
`username` varchar(30) NOT NULL default '',
`bname` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
add below bname
and replace it with:
Also, how do i just show the badges on my profile page?
But is there a way to show the images, instead of the the link?