• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

PHP Reward via Code Script

Aquilla

Enthusiast
Hello

I need a php reward script (MYSQL & PHP)

i found this on ******* but no works because no have config on topic please help me :(

<?php
//Includes the database information
include("config.php");

//makes the .php?action
switch($_GET['action']) {
//the defualt page to display
default:
//Show the page for the user to cliam a reward
echo "<form method=\"POST\" action=\"?action=claim\">
<input type=\"text\" name=\"n1\" size=\"5\" maxlength=\"4\">-<input type=\"text\" name=\"n2\" size=\"5\" maxlength=\"4\">-<input type=\"text\" name=\"n3\" size=\"5\" maxlength=\"4\">
<input type=\"submit\" value=\"Claim\" name=\"claim\"></form>";
break;

case "claim":
//posts the data
$n1 = $_POST[n1];
$n2 = $_POST[n2];
$n3 = $_POST[n3];
//check if the code exists in the database
$getcode=mysql_query("SELECT * FROM rewards where code = '" . $n1 . $n2 . $n3 . "'");
$getcode = mysql_num_rows($getcode);
if ($getcode == 0)
{
//If code does not exists give error
echo ("Invalid Reward code!");
}
else
{
//if code exists get db ifo
$code=mysql_query("SELECT * FROM rewards where code = '" . $n1 . $n2 . $n3 . "'");
$code2 = mysql_fetch_array($code);
//change the varible
$amount = $code2[reward];
//adds the points
$add = mysql_query("SELECT * FROM users WHERE username = '".$logged['username']."'") or die(mysql_error());
$add = mysql_fetch_array($add) or die(mysql_error());
$points = $add['points'] + $amount;
$update = mysql_query("UPDATE users SET points = '".$points."' WHERE username = '".$logged['username']."'") or die(mysql_error());
//UPDATE THE LINE ABOVE WITH YOUR OWN SQL DATA
//deletes the old code so it can not be used again
$delete = mysql_query("DELETE FROM `rewards` WHERE code = '" . $n1 . $n2 . $n3 . "'");
//tells the the got the reward
echo "You claimed your reward of $amount gold";
}
break;

case "admin":
//checks if there a admin
if($logged[username] && $logged[level] ==5)
{
//form to add points to a code
echo "<form method=\"POST\" action=\"?action=addcode\">
Reward Points: <input type=\"text\" name=\"reward\" size=\"10\" maxlength=\"5\">
<br><input type=\"submit\" value=\"Add Reward\" name=\"add\"></form>";
}
break;

case "addcode":
//checks if there a admin
if($logged[username] && $logged[level] >=5)
{
//letter what can be used in the code
$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//random 4 letter codes
$r1 = substr(str_shuffle($alphanum), 0, 4);
$r2 = substr(str_shuffle($alphanum), 0, 4);
$r3 = substr(str_shuffle($alphanum), 0, 4);
//gets the amount from a post
$reward = $_POST[reward];
//insert the code and reward into the database
$query = mysql_query("INSERT INTO rewards (code, reward) VALUES('$r1$r2$r3','$reward')");
//echos the code out
echo " +===================================+<br>
| Gold Center
|<br>
+===================================+<br>
| Code: $r1 - $r2 - $r3<br> | Reward: $reward<br>
+===================================+";
}
break;
}
?>
 

Vitrex

Moderator
Answer me 2 questions and i will do that, from what cms that script AND on what cms you wanna use it? :)
 

Aquilla

Enthusiast
MYSQL TABLE :

CREATE TABLE `rewards` (
`id` int(11) NOT NULL auto_increment,
`code` varchar(30) NOT NULL default '',
`reward` varchar(30) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

I create a website for a PBlackout server and i need this script but i can't fix this script ;(

WEBSITE MODEL :

52OMItl.jpg
 

Vitrex

Moderator
i'll back home after few hours and will take a look ;)
EDIT !

Here is config.php file i think , bcs all you need is database info and mysql_connect function :

PHP:
$host = "localhost";
$database = "databasename";
$user = "root";
$password "password";
$con = mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db($database,$con) or die(mysql_error());

and find this :
PHP:
break; 
} 
?>

and Change for this i think for "Security"
PHP:
break; 
} 
mysql_close($con);
?>

Didn't checked the whole script you gave for errors, feel free to ask if something don't work.
 
Last edited:

Vitrex

Moderator
Sorry, i missed " = " in one place, and edited code to hide warnings about mysql since it's outdadet
Code:
<?php
$host = "localhost";
$database = "databasename";
$user = "root";
$password = "password";
$con = @mysql_connect($host,$user,$password) or die(mysql_error());
@mysql_select_db($database,$con) or die(mysql_error());  
?>
 
Top