· 6 years ago · Jul 02, 2019, 11:00 PM
1<?php
2/*
3 * To check for player key if exist in database or not.
4 * Checks if the player key exists and registered in database.
5 */
6// DATABASE CONNECTION:
7// Define the database information.
8$hostname = "xxxx";
9$username = "xxxx";
10$password = "xxxx";
11$database = "xxxx";
12
13// Opening Database Connection.
14$cxn = mysqli_connect($hostname, $username, $password, $database) or die("Couldn't connect to GC server.");
15
16// Check to see if a POST request has been submitted.
17if (! empty($_POST)) {
18 // A POST request was submitted, so define the variables.
19 $ID = $_POST['playerKey'];
20
21 // Create the query and send it to the database.
22 $sql = "SELECT * FROM player WHERE ID = '" . $ID . "'";
23 $result = mysqli_query($cxn, $sql);
24
25 // If the database finds at least one row...
26 if (mysqli_num_rows($result) > 0) {
27 $data = mysqli_fetch_assoc($result);
28 echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?playerKey=' . $data['ID'];
29 // If the avatar is not found.
30 } else {
31 echo "Player Doesn't Exist!";
32 }
33} else {
34 // A POST request was not submitted, so display an error.
35 $ID = $_GET['playerKey'];
36 $httpreturn = urldecode($_GET['responseURL']);
37 $sql = "SELECT * FROM InventoryView WHERE ID = '" . $ID . "' AND Item = 'coins'";
38 $result = mysqli_query($cxn, $sql);
39
40 if(isset($_POST['submit'])) {
41 echo "<meta http-equiv='refresh' content='5'>";
42 }
43
44 if (mysqli_num_rows($result) > 0) {
45 $data = mysqli_fetch_assoc($result);
46 $coins = $data['Quantity'];
47 $gold = floor($coins / 10000);
48 $coins = $coins % 10000;
49 $silver = floor($coins / 100);
50 $copper = floor($coins % 100);
51
52 echo "<body>\n";
53 echo "<link rel=\"stylesheet\" href=\"/css/style.css\">\n";
54 echo " <head>\n";
55 echo "\n";
56 echo " </head>\n";
57 echo " <h1>";
58
59 echo $data['Player Name'] . '\'s Inventory';
60 echo " </h1>\n";
61 echo " <h1 style=\"color:white;font-size:46px;text-slign:center;width: 100%;\">Gold: $gold Silver: $silver Copper: $copper</h1>\n";
62 echo " <table class=\"cinereousTable\" vertical-align: middle;>\n";
63 echo " <thead>\n";
64 echo " <tr>\n";
65 echo " <th>Item :</th>\n";
66 echo " <th>Quantity</th>\n";
67 echo " <th>Action</th>\n";
68 echo " </tr>\n";
69 echo " </thead>\n";
70 echo " <tbody>\n";
71 echo " <iframe name=\"votar\" style=\"display:none;\"></iframe>";
72
73 $sql2 = "SELECT * FROM InventoryView WHERE ID = '" . $ID . "'";
74 $result2 = mysqli_query($cxn, $sql2);
75 $data2 = mysqli_fetch_assoc($result2);
76 while ($data2 = mysqli_fetch_assoc($result2)) {
77 echo " <tr>\n";
78 echo " <td>\n";
79 echo $data2['Item'];
80 echo " </td>\n";
81 echo " <td>\n";
82 echo $data2['Quantity'];
83 echo " </td>";
84 $itemID = $data2['Item_ID'];
85 $userID = $data2['ID'];
86 echo "<td width=\"10%\"><form id=\"form1\" method=\"post\" action=\"$httpreturn\" target=\"votar\"><input name=\"command\" type=\"hidden\" value=\"useItem\"><input name=\"itemID\" type=\"hidden\" value=\"$itemID\"><input name=\"userID\" type=\"hidden\" value=\"$userID\"><input name=\"submit\" type=\"submit\" value=\"Use\"></form>";
87 echo "<div><form id=\"form2\" method=\"post\" action=\"$httpreturn\" target=\"votar\"><input name=\"command\" type=\"hidden\" value=\"dropItem\"><input name=\"Item_ID\" type=\"hidden\" value=\"$itemID\"><input name=\"playerKey\" type=\"hidden\" value=\"$userID\"><input name=\"submit\" type=\"submit\" value=\"Drop\"><input name=\"itemAmount\" type=\"visable\" value=\"0\"></form></div></td>";
88 echo "</tr>";
89 }
90 echo "<tr></tr>\n";
91 echo " </tbody>\n";
92 echo "\n";
93 echo " </table>\n";
94 echo " \n";
95 echo "</body>";
96 } else {
97 echo '$ID';
98 }
99}
100?>