Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Include config file
- require_once "config.php";
- // Define variables and initialize with empty values
- $Player_Name = $Player_Level=$Player_Town=$Troop_Donated = $Troop_Received = $Clan_War=$League_War = "";
- $Player_Name_err = $Player_Level_err = $Player_Town_err = $Troop_Donated_err = $Troop_Received_err=$Clan_War_err = $League_War_err = "";
- // Processing form data when form is submitted
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- // Validate Player Name
- $input_player_name = trim($_POST["Player_Name"]);
- if(empty($input_player_name )){
- $Player_Name_err = "Please enter a player name.";
- } else{
- $Player_Name = $input_player_name ;
- }
- //Validate player are availability for registering league war
- $input_League_War=trim($_POST["League_War"]);
- if(empty($input_League_War)){
- $League_War_err="Please enter players availabilities of attending clan league";
- }else{
- $League_War=$input_League_War;
- }
- //Validate Player Level
- $input_Player_Level=trim($_POST["Player_Level"]);
- if(empty($input_Player_Level)){
- $Player_Level_err="Please enter a player level.";
- }else{
- $Player_Level=$input_Player_Level;
- }
- //Validate Player Town
- $input_Player_Town=trim($_POST["Player_Town"]);
- if(empty($input_Player_Town)){
- $Player_Town_err="Please enter player town level";
- }elseif(!ctype_digit($input_Player_Town)){
- $Player_Town_err="Please enter a positive number for the player town level";
- }else{
- $Player_Town=$input_Player_Town;
- }
- //Validate Player Troop Donate
- $input_Troop_Donate=trim($_POST["Troop_Donated"]);
- if(empty($input_Troop_Donate)){
- $Troop_Donated_err="Please enter player amount of troop donated";
- }elseif(!ctype_digit($input_Troop_Donate)){
- $Troop_Donated_err="Please enter amount for positive number of troop donated";
- }else{
- $Troop_Donated=$input_Troop_Donate;
- }
- //Validate Player Troop Received
- $input_Troop_Received=trim($_POST["Troop_Received"]);
- if(empty($input_Troop_Received)){
- $Troop_Received_err="Please enter player amount of troop received";
- }elseif(!ctype_digit($input_Troop_Received)){
- $Troop_Received_err="Please enter amount for positive number of troop received";
- }else{
- $Troop_Received=$input_Troop_Received;
- }
- //Validate player amount of times attending clan war
- $input_Clan_War=trim($_POST["Clan_War"]);
- if(empty($input_Clan_War)){
- $Clan_War_err="Please select how many times players has attend clan war per month";
- }elseif(!ctype_digit($input_Clan_War)){
- $Clan_War_err="Please enter amount for positive number of clan war attended";
- }else{
- $Clan_War=$input_Clan_War;
- }
- // Check input errors before inserting in database
- 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)){
- // Prepare an insert statement
- $sql = "INSERT INTO information(Player_Name,Player_Level,Player_Town,Troop_Donated,Troop_Received,Clan_War,League_War) VALUES (?, ?, ?,?,?,?,?)";
- if($stmt = $mysqli->prepare($sql)){
- // Bind variables to the prepared statement as parameters
- $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);
- // Set parameters
- $param_Player_Name=$Player_Name;
- $param_Player_Level=$Player_Level;
- $param_Player_Town=$Player_Town;
- $param_Troop_Donated=$Troop_Donated;
- $param_Troop_Received=$Troop_Received;
- $param_Clan_War=$Clan_War;
- $param_League_War=$League_War;
- // Attempt to execute the prepared statement
- if($stmt->execute()){
- // Records created successfully. Redirect to landing page
- header("location: index.php");
- exit();
- } else{
- echo "Oops! Something went wrong. Please try again later.";
- }
- }
- // Close statement
- $stmt->close();
- }
- // Close connection
- $mysqli->close();
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Create Record</title>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
- <style>
- .wrapper{
- width: 600px;
- margin: 0 auto;
- }
- </style>
- </head>
- <body>
- <div class="wrapper">
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-12">
- <h2 class="mt-5">Create Record</h2>
- <p>Please fill this form and submit to add employee record to the database.</p>
- <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
- <div class="form-group">
- <label>Player Name</label>
- <input type="text" name="Player_Name" class="form-control <?php echo (!empty($Player_Name_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $Player_Name; ?>">
- <span class="invalid-feedback"><?php echo $Player_Name_err;?></span>
- </div>
- <div class="form-group">
- <label>Player Level</labe>
- <input type="text" name="Player_Level" class="form-control<?php echo (!empty($Player_Level_err))?'is-invalid':'';?>"value="<?php echo $Player_Level;?>">
- <span class="invalid-feedback"><?php echo $Player_Level_err;?></span>
- </div>
- <div class="form-group">
- <label>Player Townhall</labe>
- <input type="text" name="Player_Town" class="form-control<?php echo (!empty($Player_Town_err))?'is-invalid':'';?>"value="<?php echo $Player_Town;?>">
- <span class="invalid-feedback"><?php echo $Player_Town_err;?></span>
- </div>
- <div class="form-group">
- <label>Player's Troop Donated</labe>
- <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;?>">
- <span class="invalid-feedback"><?php echo $Troop_Donated_err;?></span>
- </div>
- <div class="form-group">
- <label>Player's Troop Received</labe>
- <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;?>">
- <span class="invalid-feedback"><?php echo $Troop_Received_err;?></span>
- </div>
- <div class="form-group">
- <label>Amount of clan war attended</label>
- <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;?>">
- <span class="invalid-feedback"><?php echo $Clan_War_err;?></span>
- </div>
- <div class="form-group">
- <label>League War Availability </label>
- <input type="text" name="League_War" class="form-control<?php echo(!empty($League_War_err))?'is-invalid':'';?>"value="<?php echo $League_War;?>">
- <span class="invalid-feedback"><?php echo $League_War_err;?></span>
- </div>
- <input type="submit" class="btn btn-primary" value="Submit">
- <a href="index.php" class="btn btn-secondary ml-2">Cancel</a>
- </form>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement