Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.21 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4. include "connect.php";
  5. if (!isset($_SESSION['username']) || $_SESSION['username'] == false) {
  6.     header("location: loginForm.html");
  7.  
  8. //echo "sadf";
  9. }
  10. function processCoinSubmit($dbh){
  11.     $cCountry = filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
  12.     if (!filter_has_var(INPUT_POST, "cCountry") || $cCountry == ""){
  13.         return "Please write Country of Origin";
  14.     }
  15.     $cColour = filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
  16.     if (!filter_has_var(INPUT_POST, "cColour") || $cColour == ""){
  17.         return "Please write Coin Colour";
  18.     }
  19.     $cWorth = filter_input(INPUT_POST, "cWorth", FILTER_VALIDATE_INT);
  20.     if (!filter_has_var(INPUT_POST, "cWorth") || $cWorth == ""){
  21.         return "Please write Coin Worth";
  22.     }
  23.     $cDate = filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
  24.     if (!filter_has_var(INPUT_POST, "cDate") || $cDate == ""){
  25.         return "Please write Coin Date";
  26.     }
  27.     $cDescription = filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
  28.     if (!filter_has_var(INPUT_POST, "cDescription") || $cDescription == ""){
  29.         return "Please write Coin Description";
  30.     }
  31.  
  32.         $command = "INSERT INTO MichaelsCoinCollection (CountryOfOrigin,CoinColour,CoinWorth,CoinDate,CoinDescription) VALUES (?,?,?,?,?)";
  33.         //stmt
  34.         $stmt = $dbh->prepare($command);
  35.         //array for values
  36.         $vulues = [$cCountry, $cColour, $cWorth, $cDate, $cDescription];
  37.         //execute
  38.         /*$result = */
  39.         $stmt->execute($vulues);
  40.  
  41. }
  42. if (filter_has_var(INPUT_POST, "cSubmit")) // if coin submited
  43. {
  44.     $coinResult = processCoinSubmit($dbh);
  45.     if ($coinResult !== true)
  46.         $coinError = $coinResult;
  47. }
  48. /*
  49. if(filter_has_var(INPUT_POST, "cCountry") &&
  50. filter_has_var(INPUT_POST, "cColour") &&
  51. filter_has_var(INPUT_POST, "cWorth") &&
  52. filter_has_var(INPUT_POST, "cDate") &&
  53. filter_has_var(INPUT_POST, "cDescription")) {
  54.  
  55.     $cCountry = filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
  56.     $cColour = filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
  57.     $cWorth = filter_input(INPUT_POST, "cWorth", FILTER_VALIDATE_INT);
  58.     $cDate = filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
  59.     $cDescription = filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
  60.  
  61.     //if everything is set
  62.     $command = "INSERT INTO MichaelsCoinCollection (CountryOfOrigin,CoinColour,CoinWorth,CoinDate,CoinDescription) VALUES (?,?,?,?,?)";
  63.     //stmt
  64.     $stmt = $dbh->prepare($command);
  65.     //array for values
  66.     $vulues = [$cCountry, $cColour, $cWorth, $cDate, $cDescription];
  67.     //execute
  68.     $result = $stmt->execute($vulues);
  69. }
  70. */
  71.  
  72.  
  73.  
  74. ?><!DOCTYPE html>
  75. <html>
  76.     <head>
  77.         <meta charset="UTF-8">
  78.         <title></title>
  79.         <style>
  80.             .stable {
  81.                 border-spacing: 2px;
  82.                 border-collapse: separate;
  83.                 background-color: #aaa;
  84.             }
  85.             .stable td {
  86.                 background: white;
  87.             }
  88.         </style>
  89.     </head>
  90.     <body>
  91.         <?php if(isset($coinError)){
  92.             echo $coinError;
  93.         }
  94.         ?>
  95.         <form method="post"  action="tableManage.php">
  96.             <table>
  97.                 <tr>
  98.                     <td>
  99.                         <p>Country of Origin:</p>
  100.                         <input type="text" name="cCountry" value="<?php
  101.                                if(filter_has_var(INPUT_POST, "cCountry"))
  102.                                 echo filter_input(INPUT_POST, "cCountry", FILTER_SANITIZE_STRING);
  103.                                ?>">
  104.                     </td>
  105.                     <td>
  106.                         <p>Coin colour:</p>
  107.                         <input type="text" name="cColour" value="<?php
  108.                         if(filter_has_var(INPUT_POST, "cColour"))
  109.                             echo filter_input(INPUT_POST, "cColour", FILTER_SANITIZE_STRING);
  110.                         ?>">
  111.                     </td>
  112.                 </tr>
  113.                 <tr>
  114.                     <td>
  115.                         <p>Coin worth:</p>
  116.                         <input type="number" name="cWorth" value="<?php
  117.                         if(filter_has_var(INPUT_POST, "cWorth"))
  118.                             echo filter_input(INPUT_POST, "cWorth", FILTER_SANITIZE_STRING);
  119.                         ?>">
  120.                     </td>
  121.                     <td>
  122.                         <p>Coin Date:</p>
  123.                         <input type="date" name="cDate" value="<?php
  124.                         if(filter_has_var(INPUT_POST, "cDate"))
  125.                             echo filter_input(INPUT_POST, "cDate", FILTER_SANITIZE_STRING);
  126.                         ?>">
  127.                     </td>
  128.                 </tr>
  129.                 <tr>
  130.                     <td colspan="2">
  131.                         <p>Coin Description:</p>
  132.                         <input type="text" name="cDescription" value="<?php
  133.                         if(filter_has_var(INPUT_POST, "cDescription"))
  134.                             echo filter_input(INPUT_POST, "cDescription", FILTER_SANITIZE_STRING);
  135.                         ?>">
  136.                     </td>
  137.                 </tr>
  138.             </table>
  139.  
  140.             <input type="submit" name="cSubmit" value="Insert">
  141.         </form>
  142.         <table class="stable">
  143.             <tr>
  144.                 <th></th>
  145.                 <th>CountryOfOrigin</th>
  146.                 <th>CoinColour</th>
  147.                 <th>CoinWorth</th>
  148.                 <th>CoinDate</th>
  149.                 <th>CoinDescription</th>
  150.             </tr>
  151.             <?php
  152.             $command = "SELECT * FROM MichaelsCoinCollection Order By CoinID";
  153.             $result = $dbh->query($command);
  154.             while($row = $result->fetch()){
  155.                 ?>
  156.                 <tr>
  157.                     <td>
  158.                         <a href="updateScript.php?id=<?=$row['CoinID']?>">
  159.                             <button>Edit</button>
  160.                         </a>
  161.                     </td>
  162.                     <td><?=$row['CountryOfOrigin']?></td>
  163.                     <td><?=$row['CoinColour']?></td>
  164.                     <td><?=$row['CoinWorth']?></td>
  165.                     <td><?=$row['CoinDate']?></td>
  166.                     <td><?=$row['CoinDescription']?></td>
  167.                 </tr>
  168.             <?php } ?>
  169.         </table>
  170.     </body>
  171. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement