Hey guys,
I've seen some hotels have a lottery, so here you go
Lottery.php
PHP Code:
<?php
$Query = mysql_query("SELECT * FROM lottery WHERE username = '". $_SESSION['user']['username'] ."'");
IF($profile = mysql_fetch_array($Query)){
$Figure_1 = mysql_real_escape_string($profile['Figure_1']);
$Figure_2 = mysql_real_escape_string($profile['Figure_2']);
$Figure_3 = mysql_real_escape_string($profile['Figure_3']);
?>
<p>You have already entered!</p>
<select>
<option><?php echo $Figure_1; ?></option>
</select>
<select>
<option><?php echo $Figure_2; ?></option>
</select>
<select>
<option><?php echo $Figure_3; ?></option>
</select>
<?php } else { ?>
<form action="lottery2" method="post"><div style="color:#D8000C; background-color:#FFBABA; border:1px solid #000000; padding:2px;"/>NOTE: This will cost you <u>5000</u> coins</div><br>
<select id="Figure_1" name="Figure_1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<select id="Figure_2" name="Figure_2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<select id="Figure_3" name="Figure_3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select><br><br>
<input type="submit" id="submit" value="Submit" />
</form>
<?php } ?>
Lottery2.php
PHP Code:
##->Inserting values in database
$cost = '5000'; // How much each lottery ticket will cost
// Grabbing the POST'ed figures
$Figure_1 = mysql_real_escape_string($_POST["Figure_1"]);
$Figure_2 = mysql_real_escape_string($_POST["Figure_2"]);
$Figure_3 = mysql_real_escape_string($_POST["Figure_3"]);
$userCoins = "" . $_SESSION['user']['credits'] . "";
// If users coins are below the lottery cost, we'll send the header as an error
if($userCoins < $cost)
{
Header("Location: me?Error?=Balance");
}
else {
// Taking away the cost of lottery to the users account
$coins = mysql_query("UPDATE `users` SET `credits` = credits - ". $cost ." WHERE username = '" . $_SESSION['user']['username'] . "'");
// Inserting the values into database, we'll send the header as successful
$sql = mysql_query("INSERT INTO `lottery` (Username, Figure_1, Figure_2, Figure_3) VALUES ('". $_SESSION['user']['username'] ."', '". $Figure_1 . "', '". $Figure_2 . "', '". $Figure_3 .")");
Header("Location: me?successful");
}
Lottery.sql
Code:
-- ----------------------------
-- Table structure for `lottery`
-- ----------------------------
DROP TABLE IF EXISTS `lottery`;
CREATE TABLE `lottery` (
`Username` varchar(50) NOT NULL,
`Figure_1` varchar(1) NOT NULL,
`Figure_2` varchar(1) NOT NULL,
`Figure_3` varchar(1) NOT NULL,
PRIMARY KEY (`Username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ------------------------
Place this as a page in your housekeeping or any private file no one knows about
PHP Code:
<?php
// MySQL connection
$host = "localhost";
$user = "root";
$pass = "root";
$data = "rev_phoenix";
$connection = mysql_connect($host,$user,$pass)
or die("Could not connect: ".mysql_error());
mysql_select_db($data,$connection)
or die("Error in selecting the database:".mysql_error());
$prize = "5000"; // Prize
$Query1 = mysql_Query("SELECT * FROM lottery ORDER BY RAND() LIMIT 1");
IF($profile = mysql_fetch_array($Query1)){
$username = mysql_real_escape_string($profile['Username']);
$Figure_1 = mysql_real_escape_string($profile['Figure_1']);
$Figure_2 = mysql_real_escape_string($profile['Figure_2']);
$Figure_3 = mysql_real_escape_string($profile['Figure_3']);
$sql1 = mysql_Query("UPDATE `users` SET `credits` = credits + ".$prize." WHERE username = '".$username."'");
echo "<div style='padding:10px;background-color:green;border-radius:3px;font-family:arial;font-size:12px;color:#FFF;text-align:center;'><b>" . $username . "</b> " . $Figure_1 . " - " . $Figure_2 . " - " . $Figure_3 . " Has been awarded ". $prize . " coins!</div>";
$empty = mysql_query ("truncate table `lottery`"); // Emptying the table
}
else {
echo "<div style='padding:10px;background-color:green;border-radius:3px;font-family:arial;font-size:12px;color:#FFF;text-align:center;'>Error no entry in database!</div>";
}
?>
Once you visit this page it will
-> Select a random row to win
-> Give the user x amount of credits
-> Empty the table
Play around with the pages, most likely visit the page once a week?
With
Lottery.php you can just put it in a div container. Find any errors PM me
Sorry if this is already released anyways.. thanks.