PDA

View Full Version : [Tutorial] Rares Values System.



RyanS
16-09-2006, 12:08 PM
Can't be bothered to sell it soo..

Ok start by running the following queries.



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 ;


Now make a file called 'db.php' and put the following in it:



<?

$connection = mysql_connect("localhost","USERNAME","PASSWORD"); //Connects to the database

mysql_select_db(DATABASENAME) or die(mysql_error()); //Selects the database to read from.

?>


Next up make 'add_rv.php'



<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 now make 'create_rv.php'



<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>


Ok that will add a rare value, but how can we add it into a category when there is none???

Make addcat.php



<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>


Can't really comment in that as theres no PHP ;)

Make addcat2.php now



<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_1.php to show the categorys :)



<?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 now make values_2.php to show the rares from the category you choose in the values_1.php file :)



<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>&nbsp;"; //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>


Ok nearly done, now to make the file to edit the rares, this is proberly the biggest file yet, call it edit_rare.php :)



<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>


And thats that ^_^

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)

VersionUpdate
16-09-2006, 12:09 PM
Sticky it , its quality and maybe habbox.com may want to use it?

Eternity
16-09-2006, 12:10 PM
I don't like it, shoddy.

RyanS
16-09-2006, 12:10 PM
Doubt it, might come in useful for many people i had a pm asking for it for free so here it is ^_^

Kymux
16-09-2006, 12:12 PM
It needs a little touching up on some parts in the addcat section. But apat from that sticky wirthy xD

RyanS
16-09-2006, 12:16 PM
Anyone can edit it, i cant make it look great for everyones needs they cant edit it persoanlly.

[Oli]
16-09-2006, 12:17 PM
Nice tutorial

Greets,
Olivier Pauwels.

-::Mr.Dave::-
16-09-2006, 12:21 PM
Nice

thanks for this +rep

Mods you must sticky this

YouFail
16-09-2006, 01:08 PM
Very nice of you Ryan. You have been in a helping mood today. I've not tried it but it looks quite good and due to what has been said I think it must be quite good.

+Rep for you :)

Luckyrare
16-09-2006, 01:54 PM
Nice but Habbox will not use it since they have their own.

Sygon.
16-09-2006, 01:55 PM
not a tutorial as you didnt explain the code.

RyanS
16-09-2006, 02:20 PM
Sygon was that sarcastic?

[Oli]
16-09-2006, 02:29 PM
Sygon was that sarcastic?

I think he means, that in most tut's people explain the code like ex:
(look at the orange part, those things u didnt include in ur tutorial.)


echo include('home.php');
// This would include the Homepage home.php we made ...

RyanS
16-09-2006, 02:39 PM
Theres a code explaining what it does on near enough every line :/

RyanS
22-09-2006, 06:10 PM
BUMP.. Anyone using this?

J1MI (Forum Moderator) - Please don't double post / bump old threads.

Josh-H
22-09-2006, 06:11 PM
Fab :)

:D

RYANNNNN
22-09-2006, 07:03 PM
I could exploit this.

RyanS
22-09-2006, 07:05 PM
Wow your leet.

Lysine
28-09-2006, 01:36 PM
I am having a bit of trouble doing this system. I get this error when i add a Value


Error during the execution of the MySQL query : Table 'hablaugh_rares.categories' doesn't exist


I get this error in the create_rv.php file. If you know what the problem is please tell me :)

RYANNNNN
28-09-2006, 01:40 PM
Don't use it, it's not safe.

shenk.
28-09-2006, 01:56 PM
That's quite nice... lol x)

Lysine
28-09-2006, 02:53 PM
Anyone Help?

RyanS
28-09-2006, 04:18 PM
Lysine you have to run the MySQL into your database.

Zuex
28-09-2006, 04:43 PM
[Stickies] I wont ever use it but heh, if it works, why not?

Panther
28-09-2006, 08:18 PM
Nice +rep to you!

Lysine
29-09-2006, 11:52 AM
I am having a bit of trouble doing this system. I get this error when i add a Value



Error during the execution of the MySQL query : Table 'hablaugh_rares.categories' doesn't exist

I get this error in the create_rv.php file. If you know what the problem is please tell me

Moh
29-09-2006, 01:23 PM
I am having a bit of trouble doing this system. I get this error when i add a Value




I get this error in the create_rv.php file. If you know what the problem is please tell me

I have same problem, can some 1 help lol. Iv tried editing it, but didnt work

itprotj
26-10-2006, 09:18 AM
Having SAME Problem!! HELP PLEASE

*Bump

ScottDiamond
26-10-2006, 07:16 PM
Have yous changed the database settings to your own?

Also, do you need a Database User, RyanS?

Want to hide these adverts? Register an account for free!