Dec
Tongue Boxing Champion 2023
- May 30, 2017
- 448
- 281
PHP:
$enable = array(
"buyLotteryTicket" => true,
"lottery" => true
);
function randomChance($min, $max) {
Return random_int($min, $max) ;
}
public function randomLotteryNumber() {
$randomNum1 = randomChance(0, 9);
$randomNum2 = randomChance(0, 9);
$randomNum3 = randomChance(0, 9);
$randomNum4 = randomChance(0, 9);
$lotteryNumber = $randomNum1.$randomNum2.$randomNum3.$randomNum4;
return $lotteryNumber;
}
public function lottery() {
global $db, $enable;
if ($enable['lottery'] == true) {
if (isset($_POST['lottery'])) {
$getLottery = $db->prepare("
SELECT * FROM cms_lottery WHERE active = '1'
");
$getLottery->execute();
if ($getLottery->RowCount() > 0) {
$winningTicketNumbers = $getLottery->fetch();
$getLotteryTickets = $db->prepare("SELECT * FROM cms_lottery_tickets WHERE ticket_number = :winninglotteryticket");
$getLotteryTickets->bindParam(":winninglotteryticket", $winningTicketNumbers['lottery_ticket']);
$getLotteryTickets->execute();
if ($getLotteryTickets->RowCount() > 0) {
while ($winners = $getLotteryTickets->fetch()) {
$giftPrize = $db->prepare("UPDATE users SET {$winningTicketNumbers['type']} = coins + {$winningTicketNumbers['amount']} WHERE id = :user_id");
$giftPrize->bindParam(":user_id", $winners['user_id']);
$giftPrize->execute();
}
$deleteWinningTicket = $db->prepare("DELETE from cms_lottery WHERE id = :winninglotteryticket");
$deleteWinningTicket->bindParam(":winninglotteryticket", $winningTicketNumbers['id']);
$deleteWinningTicket->execute();
$deleteOldTickets = $db->prepare("TRUNCATE TABLE cms_lottery_tickets");
$deleteOldTickets->execute();
} else {
echo "No tickets were bought this week";
}
}
}
}
}
public function buyLotteryTicket() {
global $db, $enable;
if ($enable['buyLotteryTicket'] == true) {
if (isset($_POST['buyLotteryTicket'])) {
if (!empty($_POST['num1']) && $_POST['num1'] < 10 && ctype_digit($_POST['num1'])) {
if (!empty($_POST['num2']) && $_POST['num2'] < 10 && ctype_digit($_POST['num2'])) {
if (!empty($_POST['num3']) && $_POST['num3'] < 10 && ctype_digit($_POST['num3'])) {
if (!empty($_POST['num4']) && $_POST['num4'] < 10 && ctype_digit($_POST['num4'])) {
$lotteryTicket = $_POST['num1'].$_POST['num2'].$_POST['num3'].$_POST['num4'];
$date = 123;
$getLotteryTicket = $db->prepare("
INSERT INTO cms_lottery_tickets (user_id, ticket_number, buy_date) VALUES (:user_id, :ticket_number, :buy_date)
");
$getLotteryTicket->bindParam(":user_id", $_SESSION['id']);
$getLotteryTicket->bindParam(":ticket_number", $lotteryTicket);
$getLotteryTicket->bindParam(":buy_date", $date);
$getLotteryTicket->execute();
} else {
echo "Something wrong with number picker field 4";
}
} else {
echo "Something wrong with number picker field 3";
}
} else {
echo "Something wrong with number picker field 2";
}
} else {
echo "Something wrong with number picker field 1";
}
}
}
}
HTML:
<form method='POST'>
<input name="num1" type="number" min="0" max="9" placeholder="0-9"></input>
<input name="num2" type="number" min="0" max="9" placeholder="0-9"></input>
<input name="num3" type="number" min="0" max="9" placeholder="0-9"></input>
<input name="num4" type="number" min="0" max="9" placeholder="0-9"></input>
<button type="submit" name="buyLotteryTicket">buy ticket</button>
</form>
<form method="POST">
<button name="lottery" type="submit">run the lottery</button>
</form>
lottery sql:
You must be registered for see links
tickets sql:
You must be registered for see links
i couldnt be arsed to sort the dates out do it yourself
Last edited: