Advertisement
backlight0815

Untitled

Mar 23rd, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. <?php
  2. // Include config file
  3. require_once "config.php";
  4.  
  5. // Define variables and initialize with empty values
  6. $Player_Name = $Player_Level=$Player_Town=$Troop_Donated = $Troop_Received = $Clan_War=$League_War = "";
  7. $Player_Name_err = $Player_Level_err = $Player_Town_err = $Troop_Donated_err = $Troop_Received_err=$Clan_War_err = $League_War_err = "";
  8.  
  9. // Processing form data when form is submitted
  10. if($_SERVER["REQUEST_METHOD"] == "POST"){
  11. // Validate Player Name
  12. $input_player_name = trim($_POST["Player_Name"]);
  13. if(empty($input_player_name )){
  14. $Player_Name_err = "Please enter a player name.";
  15.  
  16. } else{
  17. $Player_Name = $input_player_name ;
  18. }
  19.  
  20. //Validate player are availability for registering league war
  21. $input_League_War=trim($_POST["League_War"]);
  22. if(empty($input_League_War)){
  23. $League_War_err="Please enter players availabilities of attending clan league";
  24. }else{
  25. $League_War=$input_League_War;
  26. }
  27.  
  28.  
  29. //Validate Player Level
  30. $input_Player_Level=trim($_POST["Player_Level"]);
  31. if(empty($input_Player_Level)){
  32. $Player_Level_err="Please enter a player level.";
  33. }else{
  34. $Player_Level=$input_Player_Level;
  35. }
  36. //Validate Player Town
  37. $input_Player_Town=trim($_POST["Player_Town"]);
  38. if(empty($input_Player_Town)){
  39. $Player_Town_err="Please enter player town level";
  40. }elseif(!ctype_digit($input_Player_Town)){
  41. $Player_Town_err="Please enter a positive number for the player town level";
  42. }else{
  43. $Player_Town=$input_Player_Town;
  44. }
  45.  
  46. //Validate Player Troop Donate
  47. $input_Troop_Donate=trim($_POST["Troop_Donated"]);
  48. if(empty($input_Troop_Donate)){
  49. $Troop_Donated_err="Please enter player amount of troop donated";
  50. }elseif(!ctype_digit($input_Troop_Donate)){
  51. $Troop_Donated_err="Please enter amount for positive number of troop donated";
  52. }else{
  53. $Troop_Donated=$input_Troop_Donate;
  54. }
  55. //Validate Player Troop Received
  56. $input_Troop_Received=trim($_POST["Troop_Received"]);
  57. if(empty($input_Troop_Received)){
  58. $Troop_Received_err="Please enter player amount of troop received";
  59. }elseif(!ctype_digit($input_Troop_Received)){
  60. $Troop_Received_err="Please enter amount for positive number of troop received";
  61. }else{
  62. $Troop_Received=$input_Troop_Received;
  63. }
  64. //Validate player amount of times attending clan war
  65. $input_Clan_War=trim($_POST["Clan_War"]);
  66. if(empty($input_Clan_War)){
  67. $Clan_War_err="Please select how many times players has attend clan war per month";
  68. }elseif(!ctype_digit($input_Clan_War)){
  69. $Clan_War_err="Please enter amount for positive number of clan war attended";
  70. }else{
  71. $Clan_War=$input_Clan_War;
  72. }
  73.  
  74. // Check input errors before inserting in database
  75. if(empty($Player_Name_err)&& empty($Player_Level_err)&&empty($Player_Town_err)&&empty($Troop_Donated_err)&&empty($Troop_Received_err)&&empty($Clan_War_err)&&empty($League_War_err)){
  76. // Prepare an insert statement
  77. $sql = "INSERT INTO information(Player_Name,Player_Level,Player_Town,Troop_Donated,Troop_Received,Clan_War,League_War) VALUES (?, ?, ?,?,?,?,?)";
  78.  
  79. if($stmt = $mysqli->prepare($sql)){
  80. // Bind variables to the prepared statement as parameters
  81. $stmt->bind_param("siiiiis", $param_Player_Name,$param_Player_Level,$param_Player_Town,$param_Troop_Donated,$param_Troop_Received,$param_Clan_War,$param_League_war);
  82.  
  83. // Set parameters
  84. $param_Player_Name=$Player_Name;
  85. $param_Player_Level=$Player_Level;
  86. $param_Player_Town=$Player_Town;
  87. $param_Troop_Donated=$Troop_Donated;
  88. $param_Troop_Received=$Troop_Received;
  89. $param_Clan_War=$Clan_War;
  90. $param_League_War=$League_War;
  91.  
  92. // Attempt to execute the prepared statement
  93. if($stmt->execute()){
  94. // Records created successfully. Redirect to landing page
  95. header("location: index.php");
  96. exit();
  97. } else{
  98. echo "Oops! Something went wrong. Please try again later.";
  99. }
  100. }
  101.  
  102. // Close statement
  103. $stmt->close();
  104. }
  105.  
  106. // Close connection
  107. $mysqli->close();
  108. }
  109.  
  110. ?>
  111.  
  112. <!DOCTYPE html>
  113. <html lang="en">
  114. <head>
  115. <meta charset="UTF-8">
  116. <title>Create Record</title>
  117. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  118. <style>
  119. .wrapper{
  120. width: 600px;
  121. margin: 0 auto;
  122. }
  123. </style>
  124. </head>
  125. <body>
  126. <div class="wrapper">
  127. <div class="container-fluid">
  128. <div class="row">
  129. <div class="col-md-12">
  130. <h2 class="mt-5">Create Record</h2>
  131. <p>Please fill this form and submit to add employee record to the database.</p>
  132. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
  133. <div class="form-group">
  134. <label>Player Name</label>
  135. <input type="text" name="Player_Name" class="form-control <?php echo (!empty($Player_Name_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Player_Name; ?>">
  136. <span class="invalid-feedback"><?php echo $Player_Name_err;?></span>
  137. </div>
  138. <div class="form-group">
  139. <label>Player Level</labe>
  140. <input type="text" name="Player_Level" class="form-control<?php echo (!empty($Player_Level_err))?'is-invalid':'';?>"value="<?php echo $Player_Level;?>">
  141. <span class="invalid-feedback"><?php echo $Player_Level_err;?></span>
  142. </div>
  143. <div class="form-group">
  144. <label>Player Townhall</labe>
  145. <input type="text" name="Player_Town" class="form-control<?php echo (!empty($Player_Town_err))?'is-invalid':'';?>"value="<?php echo $Player_Town;?>">
  146. <span class="invalid-feedback"><?php echo $Player_Town_err;?></span>
  147. </div>
  148.  
  149. <div class="form-group">
  150. <label>Player's Troop Donated</labe>
  151. <input type="number" name="Troop_Donated" min="1" max="5" class="form-control<?php echo (!empty($Troop_Donated_err))?'is-invalid':'';?>"value="<?php echo $Troop_Donated;?>">
  152. <span class="invalid-feedback"><?php echo $Troop_Donated_err;?></span>
  153. </div>
  154.  
  155. <div class="form-group">
  156. <label>Player's Troop Received</labe>
  157. <input type="number" name="Troop_Received" min="1" max="5" class="form-control<?php echo (!empty($Troop_Received_err))?'is-invalid':'';?>"value="<?php echo $Troop_Received;?>">
  158. <span class="invalid-feedback"><?php echo $Troop_Received_err;?></span>
  159. </div>
  160.  
  161. <div class="form-group">
  162. <label>Amount of clan war attended</label>
  163. <input type="number" name="Clan_War" min="1" max="5" class="form-control<?php echo(!empty($Clan_War_err))?'is-invalid':'';?>"value="<?php echo $Clan_War;?>">
  164. <span class="invalid-feedback"><?php echo $Clan_War_err;?></span>
  165. </div>
  166. <div class="form-group">
  167. <label>League War Availability </label>
  168. <input type="text" name="League_War" class="form-control<?php echo(!empty($League_War_err))?'is-invalid':'';?>"value="<?php echo $League_War;?>">
  169. <span class="invalid-feedback"><?php echo $League_War_err;?></span>
  170. </div>
  171.  
  172.  
  173.  
  174. <input type="submit" class="btn btn-primary" value="Submit">
  175. <a href="index.php" class="btn btn-secondary ml-2">Cancel</a>
  176. </form>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </body>
  182. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement