This is lottery2.php it´s located in my default htdocs folder so NOT in the skin.
PHP Code:
<?php ##->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");
} ?><?php // MySQL connection $host = "localhost"; $user = "root"; $pass = "secret"; $data = "hidden";
$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 = "500"; // 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>"; } ?>
This is the PHP-code for the lottery. I putted in a box.
<div class="box"> <div class="heading orange"> <div class="title">Loterij</div> <div class="clear"></div> </div><?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 } ?> </div> </div>