· 6 years ago · Mar 10, 2019, 09:36 AM
1<form action="gift.php" method="get">
2<p>Enter your gift code:</p>
3<input name="code" type="text"/>
4<input type="submit" value="Submit"/>
5</form>
6
7CREATE TABLE IF NOT EXISTS `gifttable` (
8 `id` int(1) NOT NULL AUTO_INCREMENT,
9 `code` varchar(255) NOT NULL
10 PRIMARY KEY (`id`)
11) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
12
13INSERT INTO `gifttable` (
14 `id`, `code`
15 ) VALUES (
16 NULL, 'some winning code :)'
17 );
18
19if (isset($_GET['code']) && !empty($_GET['code'])) {
20 $code = mysqli_real_escape_string(urldecode($_GET['code']));
21 $query = mysqli_query($db, "SELECT * FROM `gifttable` WHERE `code` = '{$code}'");
22
23 if (mysqli_num_rows($query)) {
24 header("Location: winner.php");
25 } else {
26 header("Location: loser.php");
27 }
28} else {
29 echo "please enter a gift code";
30 exit;
31}