Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include "connect.php";
- if (!isset($_SESSION['username']) || $_SESSION['username'] == false) {
- header("location: loginForm.html");
- //echo "sadf";
- }
- function processCoinSubmit($dbh){
- $cCountry = filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
- if (!filter_has_var(INPUT_POST, "cCountry") || $cCountry == ""){
- return "Please write Country of Origin";
- }
- $cColour = filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
- if (!filter_has_var(INPUT_POST, "cColour") || $cColour == ""){
- return "Please write Coin Colour";
- }
- $cWorth = filter_input(INPUT_POST, "cWorth", FILTER_VALIDATE_INT);
- if (!filter_has_var(INPUT_POST, "cWorth") || $cWorth == ""){
- return "Please write Coin Worth";
- }
- $cDate = filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
- if (!filter_has_var(INPUT_POST, "cDate") || $cDate == ""){
- return "Please write Coin Date";
- }
- $cDescription = filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
- if (!filter_has_var(INPUT_POST, "cDescription") || $cDescription == ""){
- return "Please write Coin Description";
- }
- $command = "INSERT INTO MichaelsCoinCollection (CountryOfOrigin,CoinColour,CoinWorth,CoinDate,CoinDescription) VALUES (?,?,?,?,?)";
- //stmt
- $stmt = $dbh->prepare($command);
- //array for values
- $vulues = [$cCountry, $cColour, $cWorth, $cDate, $cDescription];
- //execute
- /*$result = */
- $stmt->execute($vulues);
- }
- if (filter_has_var(INPUT_POST, "cSubmit")) // if coin submited
- {
- $coinResult = processCoinSubmit($dbh);
- if ($coinResult !== true)
- $coinError = $coinResult;
- }
- /*
- if(filter_has_var(INPUT_POST, "cCountry") &&
- filter_has_var(INPUT_POST, "cColour") &&
- filter_has_var(INPUT_POST, "cWorth") &&
- filter_has_var(INPUT_POST, "cDate") &&
- filter_has_var(INPUT_POST, "cDescription")) {
- $cCountry = filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
- $cColour = filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
- $cWorth = filter_input(INPUT_POST, "cWorth", FILTER_VALIDATE_INT);
- $cDate = filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
- $cDescription = filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
- //if everything is set
- $command = "INSERT INTO MichaelsCoinCollection (CountryOfOrigin,CoinColour,CoinWorth,CoinDate,CoinDescription) VALUES (?,?,?,?,?)";
- //stmt
- $stmt = $dbh->prepare($command);
- //array for values
- $vulues = [$cCountry, $cColour, $cWorth, $cDate, $cDescription];
- //execute
- $result = $stmt->execute($vulues);
- }
- */
- ?><!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- <style>
- .stable {
- border-spacing: 2px;
- border-collapse: separate;
- background-color: #aaa;
- }
- .stable td {
- background: white;
- }
- </style>
- </head>
- <body>
- <?php if(isset($coinError)){
- echo $coinError;
- }
- ?>
- <form method="post" action="tableManage.php">
- <table>
- <tr>
- <td>
- <p>Country of Origin:</p>
- <input type="text" name="cCountry" value="<?php
- if(filter_has_var(INPUT_POST, "cCountry"))
- echo filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
- ?>">
- </td>
- <td>
- <p>Coin colour:</p>
- <input type="text" name="cColour" value="<?php
- if(filter_has_var(INPUT_POST, "cColour"))
- echo filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
- ?>">
- </td>
- </tr>
- <tr>
- <td>
- <p>Coin worth:</p>
- <input type="number" name="cWorth" value="<?php
- if(filter_has_var(INPUT_POST, "cWorth"))
- echo filter_input(INPUT_POST, "cWorth", FILTER_SANITIZE_STRING);
- ?>">
- </td>
- <td>
- <p>Coin Date:</p>
- <input type="date" name="cDate" value="<?php
- if(filter_has_var(INPUT_POST, "cDate"))
- echo filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
- ?>">
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <p>Coin Description:</p>
- <input type="text" name="cDescription" value="<?php
- if(filter_has_var(INPUT_POST, "cDescription"))
- echo filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
- ?>">
- </td>
- </tr>
- </table>
- <input type="submit" name="cSubmit" value="Insert">
- </form>
- <table class="stable">
- <tr>
- <th></th>
- <th>CountryOfOrigin</th>
- <th>CoinColour</th>
- <th>CoinWorth</th>
- <th>CoinDate</th>
- <th>CoinDescription</th>
- </tr>
- <?php
- $command = "SELECT * FROM MichaelsCoinCollection Order By CoinID";
- $result = $dbh->query($command);
- while($row = $result->fetch()){
- ?>
- <tr>
- <td>
- <a href="updateScript.php?id=<?=$row['CoinID']?>">
- <button>Edit</button>
- </a>
- </td>
- <td><?=$row['CountryOfOrigin']?></td>
- <td><?=$row['CoinColour']?></td>
- <td><?=$row['CoinWorth']?></td>
- <td><?=$row['CoinDate']?></td>
- <td><?=$row['CoinDescription']?></td>
- </tr>
- <?php } ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement