Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 368
0 Users 4 Guests Online

Lottery System

Hey there!

This is just a tutorial to show you how to make a lottery system to go along with your Point system/shop.

First off, you will want to open up your phpMyAdmin and enter the following query:
Code

CREATE TABLE `lottery` (
`id` INT( 11 ) NOT NULL auto_increment,
`owner` VARCHAR( 255 ) NOT NULL,
PRIMARY KEY(`id`)
);


Next, open your config file and add:
Code

$lottopts = '5';


Change the 5 to however many points you want the lotto tickets to cost.

Next make a new file in your main DIR named lottery.php and in it code something like..

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
session_start
(); //allow sessuibs
include("config.php"); //get database
switch($_GET[act]){ //make links ?act=casename
default: //make default page
$total_tickets mysql_num_rows(mysql_query("SELECT * FROM `lottery` ORDER BY `id` DESC")); //get the total tickets in the database
$total_points $total_tickets $lottopts//turn the number into real points :)
$total_user_owns mysql_num_rows(mysql_query("SELECT * FROM `lottery` WHERE `owner` = '$logged[username]';")); //get how many the logged in user has
echo "<form method=\"post\" action=\"lottery.php?act=buy\">
<table width=\"350\" border=\"1\" style=\"border: 1px solid #000000;\">
<tr>
<td width=\"80\"><b>Name</b>:</td>
<td width=\"254\">Lottery Ticket</td>
</tr>
<tr>
<td><b>Description</b>:</td>
<td>Buy a ticket see how much you can win or lose :)</td>
</tr>
<tr>
<td><b>Price</b>:</td>
<td>
$lottopts Point(s)</td>
</tr>
<tr>
<td><b>You Own</b>:</td>
<td>
$total_user_owns Ticket(s)</td>
</tr>
<tr>
<td><b>Prize</b>:</td>
<td>
$total_points Points (So Far!)</td>
</tr>
<tr>
<td><input type=\"text\" maxlength=\"2\" size=\"14\" name=\"amount\">&nbsp;<input type=\"submit\" name=\"buy\" value=\"Buy!\"></td>
</tr>
</table>"
//echo the form for buying, some general information
break; //End the default page for buying tickets
case 'buy'//the buy page
if($_POST[buy]){ //if they submitted the form
$amount_bought = (int) $_POST[amount]; //get the amount bought
if($amount_bought '10'){ //if the user bought more than 10
echo "You Can Not Buy More Then 10 Tickets"//tell them they can not get more than 10
}else{ //or if they bought exactly or less than 10
$math $amount_bought $lottopts//times the amount bought by how much the lotto ticket costs
if($logged[points] < $math){ //if they do not have enough points
echo "You Do Not Have Enough Points."//tell them
}else{ //or if they do have enough
$rmv_pts $logged[points] - $math//get rid of points from user hand.....
if($rmv_pts '0'){ //check points just in case 
echo "You Do Not Have Enough Points!"//if they don't have enough points
}else{ //or if they do have enough
$update_table mysql_query("UPDATE `members` SET `points` = '$rmv_pts' WHERE `username` = '$logged[username]';"); //update users points :S
for($i 1$i <= $amount_bought$i++){ //$i is 1, but then i is less than or equal to the amount bought then $i is increased by one UNTILL it is the same number as the amount bought :)
$insert mysql_query("INSERT INTO `lottery` (`owner`) VALUES ('$logged[username]');") or die(mysql_error()); //insert or die >:O
//end for function
echo "You Have Bought $amount_bought Ticket(s)"//tell them how many they bought.
//end second points check
//end points check
//end amount check
}else{ //or if they didn't
echo "You Can Not Visit This Page Directly"//give them what they deserve!
//end form check
break; //end the buy page
}
?>


Note: put this next file in the /home/YOURUSERNAME/ directory so no body can get to it! And i used different things for the Cron jobs filename and username thingo.

name this file LOTTERYcron.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
include("public_html/config.php"); //get config from regular site area
$admin "your_name"//put your username there
$date date("d-m-y"); //get todays date
$totaltickets mysql_num_rows(mysql_query("SELECT * FROM `lottery`")); //get total tickets
$query_lotto mysql_query("SELECT * FROM `lottery` ORDER BY RAND() ASC LIMIT 1");
$prize $totaltickets $lottopts;
$gw mysql_fetch_array($query_lotto); //get the winner :)
$winner $gw[owner]; //winner's username
$updateuser mysql_query("UPDATE `members` SET `points` = `points` + $prize WHERE `username` = '" $winner "'"); //update the users points
$msg "Hey There $winner,

<b>Congradulations! You've Won The Lottery!</b>
Total Prize: 
$prize.";
$pmmem mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" $winnder "','" $admin .  "','" $date "','Lottery Notice','" .$msg "')") or die(mysql_error()); //insert pm into table for user
$reset mysql_query("TRUNCATE `lottery`"); //empty the table
?>


Next open up Cpanel and go to Cron Jobs,
Cpanel 11:
TutorialNinja Image

Cpanel 10:
TutorialNinja Image

After that select Advanced (Unix Style) and enter the following:
Cpanel 11:
TutorialNinja Image

Cpanel 10:
TutorialNinja Image

be sure to change YOURUSERNAME and YOURNAME to your Cpanel username.
That should be it for that...
ShadowMage
Author:
Views:
4078
Rating:
Posted on Sunday 7th September 2008 at 06:29 PM
jambomb
jambomb
I think i found the solution for the PM Not sending!!

Find
Code


$pmmem = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $winnder . "','" . $admin . "','" . $date . "','Lottery Notice','" .$msg . "')") or die(mysql_error()); //insert pm into table for user



Replace with

Code

$pmmem = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $winner . "','" . $admin . "','" . $date . "','Lottery Notice','" .$msg . "')") or die(mysql_error());



Hope it works for you! it does for me :P
Posted on Sunday 7th September 2008 at 06:03 PM
jambomb
jambomb
Doesnt send the PM Guys.... plz make this work ? and bank intrest ?
Posted on Tuesday 13th November 2007 at 07:58 PM
awo
awo
The PM not Works :S
Posted on Sunday 2nd September 2007 at 05:52 PM
DanielXP
DanielXP
I have updated it, Hope it works!
Posted on Sunday 2nd September 2007 at 03:01 PM
Diablosblizz
Diablosblizz
Shadow, any luck?
Posted on Tuesday 21st August 2007 at 09:34 PM
ShadowMage
ShadowMage
i'll look into that
Posted on Tuesday 21st August 2007 at 08:24 PM
Diablosblizz
Diablosblizz
Doesn't work...

1. Doesn't private message the user.
2. Doesn't add the points, just gives the user the points in the lottery.

Example: If I bought 10, it would be 50, and then I would win and it would reset my money to 50, not add.

:S
Posted on Saturday 30th June 2007 at 01:04 PM
ShadowMage
ShadowMage
@cyruswu - this isn't the same as the one on techtuts, the Cpanel 10 images are as i do not know of any site that has Cpanel 10 x.x'
i was looking at yours for a base line but typed it all up on the PC beside i'll post a forum post for workstations later on as i can't find the PC area i took a pic of .-.
Posted on Saturday 30th June 2007 at 01:02 PM
DanielXP
DanielXP
Looks like some think I made :P

Not really that good tho with the random number for the ticket ID as then you can't delete any tickets..
Posted on Saturday 30th June 2007 at 01:02 PM
cyruswu
cyruswu
-Removed-

Please do not swear.




Mod-shadow what did you do i saw that on techtuts. lol.