Can't be bothered to sell it soo..
Ok start by running the following queries.
Now make a file called 'db.php' and put the following in it:PHP Code:CREATE TABLE `rares` (
`id` smallint(6) NOT NULL auto_increment,
`title` varchar(30) NOT NULL default '',
`category` tinyint(6) NOT NULL default '0',
`image` varchar(100) NOT NULL default '',
`date` varchar(20) NOT NULL default '',
`name` varchar(255) default '',
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=36 DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;
CREATE TABLE `cats` (
`id` tinyint(4) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
Next up make 'add_rv.php'PHP Code:<?
$connection = mysql_connect("localhost","USERNAME","PASSWORD"); //Connects to the database
mysql_select_db(DATABASENAME) or die(mysql_error()); //Selects the database to read from.
?>
Ok now make 'create_rv.php'PHP Code:<style type="text/css">
<!--
.everything {
background-color: #97CBFF;
border: 1px dashed #000000;
font-family: Verdana;
font-size: 8pt;
}
-->
</style>
<?
include("db.php");
?>
<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#97CBFF" width="500" id="AutoNumber1">
<tr>
<td width="500">
<FORM action="create_rv.php" method="post">
<font face="Verdana" size="1"><b>Welcome RVR.</b><br>Welcome to the Rares Values Management page, you can use this page to add a Rares Value, remember this can be edited later on so you dont have to make a new rare everytime it changed in value...<br><br>
<b>Name of Rare:</b><br>
<input type="text" class="everything" size="20" name="rname"><br><br>
<b>Current Value of Rare:</b>
<br><input type="text" size="20" class="everything" name="title"><br><br>
<b>URL of Rare Image:<br></b>
<input type="text" class="everything" size="20" name="image"></textarea><br><br>
<b>Which Category is the Rare In:<br></b>
<select class="everything" name="category">
<?php
include ('db.php'); //Includes the connection file
$query="SELECT name FROM cats"; //Selects the categorys from the database
$res = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Connects to the database
while ($row = mysql_fetch_array($res)) //Echos out all the catergorys
{
echo "<OPTION>$row[name]</OPTION><br>"; //Shows the categorys in a dropdown menu
} //Ends the function
?>
</select><br><br>
<input type="submit" class="everything" value="Submit">
</FORM><br>
Ok that will add a rare value, but how can we add it into a category when there is none???PHP Code:<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#97CBFF" width="500" id="AutoNumber1">
<tr>
<td width="500">
<?php
$image=$_REQUEST['image']; //Gets the image destination
$title=$_REQUEST['title']; //Gets the value
$category=$_REQUEST['category']; //Gets the category that you chose
$date = date('F jS, Y'); //Logs the date
$name = $_REQUEST['rname']; //Gets the name of the rare
include ('db.php'); //Includes the configuration file
$query = "SELECT * FROM categories WHERE name = '$category'"; //Selects the category you chose
$res = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Connects to the database
$row = mysql_fetch_array($res); //Variable for the row
$cat = $row['id']; //Variable for the ID
$query = "INSERT INTO rares VALUES ('', '$title', '$cat', '$image', '$date','$name')"; //Inserts the value into the database
$result = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Writes to the database
echo "<font face=\"Verdana\" size=\"1\"><b>Thankyou</b><br><br>The Rare Value has successfully been added."; //Says thanks for submitting a value
?>
</table></tr>
Make addcat.php
Can't really comment in that as theres no PHPPHP Code:<style type="text/css">
<!--
.everything {
background-color: #97CBFF;
border: 1px dashed #000000;
font-family: Verdana;
font-size: 8pt;
}
-->
</style>
<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#97CBFF" width="500" id="AutoNumber1">
<tr>
<td width="500">
<font face="Verdana" size="1"><b>Add Category</b><br>
Please enter a name for the Category and press done.<br><br>
<FORM ACTION="addcat2.php" METHOD="POST">
<b>Name of Category:</b><br><input type="text" class="everything" size="20" name="cagetory"><br><br>
<input type="submit" class="everything" value="Submit">
</FORM>
</table></tr>
Make addcat2.php now
Ok now make values_1.php to show the categorysPHP Code:<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#97CBFF" width="500" id="AutoNumber1">
<tr>
<td width="500">
<?php
$cat=$_REQUEST['cagetory']; //Gets the category name
include ('db.php'); //Includes the configuration file
$query="INSERT INTO cats (id, name) VALUES ('', '$cat')"; //Inserts the data into the database
$result = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Connects to database
echo "<font face=\"Verdana\" size=\"1\"><b>Category Added</b><br><br>The category has been successfully added."; //Added the cdtegory
?>
</table>
</tr>
Ok now make values_2.php to show the rares from the category you choose in the values_1.php filePHP Code:<?php
include ('db.php'); //Includes the configuration fole
$query="SELECT * FROM cats"; //Selects all the categorys from the dtabase
$res = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Connects to DB
while ($row = mysql_fetch_array($res)) //Echos out all categorys
{
echo "View <a href=\"values_2.php?id=$row[id]\">$row[name]</a><br>"; //Format to show each link to each category in, if you get me!
}
?>
Ok nearly done, now to make the file to edit the rares, this is proberly the biggest file yet, call it edit_rare.phpPHP Code:<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
<BODY onLoad="if ('Navigator' == navigator.appName) document.forms[0].reset();">
<?php
include ('db.php'); //Includes the config file
$id=$_REQUEST['id']; //Gets the id of the cateogyr you chose
$query="SELECT name FROM cats WHERE id = '$id'"; //Selects the rares from the catgegory
$res = mysql_query($query, $connection) or die ('Error during the execution of MySQL : ' . mysql_error());
$row = mysql_fetch_array($res); //Gets the row(s)
$cat = $row['name']; //The category is the row name
$query="SELECT * FROM rares WHERE category = '$id'"; //Selects the rares from this category only
$res = mysql_query($query, $connection) or die ('Error during the execution of the MySQL query : ' . mysql_error()); //Conects to the DB
while ($row = mysql_fetch_array($res)) //Echos out all rares
{
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"80\" id=\"AutoNumber1\"><tr>
<td width=\"80px\" border=\"1px\"><font face=\"Verdana\" size=\"1\"><p align=\"center\"><img src=\"$row[image]\" alt=\"Value Added on $row[date]\"><br>$row[title]</a>
</tr></table> "; //What each rare will display like
}
if (mysql_num_rows($res) == "0") //If theres no rares in this category
{
echo "The staff on this site are lazy and havent added any rares yet ^_^"; //Tells the user the breaking news
}
?>
</body>
</html>
And thats that ^_^PHP Code:<style type="text/css">
<!--
.form {
background-color: #97CBFF;
border: 1px dashed #000000;
font-family: Verdana;
font-size: 8pt;
}
-->
</style>
<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#97CBFF" width="500" id="AutoNumber1">
<tr>
<td width="500">
<?
include("db.php"); //includes config file
if($_GET[rares]) //If there is a ?rare=blabla in the URL
{
if (!$_POST[update]) //If you havent updated the rare yet
{
$rares = mysql_query("SELECT * from rares where name = '$_GET[rares]'"); //Select the rare to edit from the database where the name is the same as the rare you chose to edit
$rares = mysql_fetch_array($rares); //Makes an array of the rares
echo("<font face=\"verdana\" size=\"1\"><b>Edit A Rare</b><br /><br />
<form method=\"POST\">
Rare Name:<br />
<input type=\"text\" class=\"form\" size=\"25\" maxlength=\"40\" name=\"name\" value=\"$rares[name]\"><br /><br />
Rare Value:<br />
<input type=\"text\" class=\"form\" size=\"25\" maxlength=\"40\" name=\"value\" value=\"$rares[title]\"><br /><br />
Image:<br />
<input type=\"text\" class=\"form\" size=\"25\" maxlength=\"40\" name=\"image\" value=\"$rares[image]\"><br /><br />
<input type=\"submit\" class=\"form\" name=\"update\" value=\"Update Rare\"><br /><br />
Name MUST be left the same or the rare will NOT update.
");//Echos out the form
}
else //If they HAVE updated the rare
{
$value = htmlspecialchars($_POST[title]); //Gets the actual value
$name = htmlspecialchars($_POST[name]); //Gets the name of the rare
$image = htmlspecialchars($_POST[image]); //Gets the image destrination
echo ("<font face=\"verdana\" size=\"1\"><b>Rare Updated</b><br /><br />the rare was successfully updated."); //Say thanks for updating the rare
$update = mysql_query("Update rares set title = '$value',
name = '$name', image = '$image' where name = '$name'"); //update the database where the name is the rare you chose to edit
}
}
else //If they havent chose a rare to edit yet
{
echo("<font face=\"verdana\" size=\"1\"><b>Choose a Rare to Edit</b><br>"); //Makes the header thing at the top
$getrares = mysql_query("Select * from rares order by name asc"); //Gets all the rares from the database
while($rares = mysql_fetch_array($getrares)) //Echos out each and every rare
{
echo("<a href=\"?rares=$rares[name]\">$rares[name]</a><br />"); //Display format for each rare
}
} //Ends functions
?>
</table>
Good luck, there is no errors in this and you cant complain i haven't comented enough as there is like a comment on each line ^_^ Enjoy!
Copyright PixelResources.co.uk - Tutorials - 2006 - 2007 used on habboxforum with permission from owner (Me)







Reply With Quote







