Advertisement
Darkness4869

ConsoleMail.php

Jun 18th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.46 KB | None | 0 0
  1. <?php
  2. // Starting session
  3. session_start();
  4. // Adding the API that will handle the connection between the web application and the database.
  5. require "./StormySystems.php";
  6. ?>
  7. <!DOCTYPE html>
  8. <html lang="en">
  9.     <head>
  10.         <meta charset="UTF-8" />
  11.         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  12.         <title>
  13.             Stormy Systems
  14.         </title>
  15.         <link rel="stylesheet" href="./Stylesheets/ConsoleMail.css" />
  16.         <link rel="shortcut icon" href="./Images/Logo.ico" type="image/x-icon" />
  17.     </head>
  18.     <body>
  19.         <!-- Header -->
  20.         <header>
  21.             <div class="Logo">
  22.                 <img src="./Images/Logo.png" alt="Logo" class="Logo">
  23.             </div>
  24.             <!-- Username -->
  25.             <h4>
  26.                 <?php echo $_SESSION['UsersUsername']; ?>
  27.             </h4>
  28.             <!-- It will redirect the user to the log out process. -->
  29.             <a href="../Logout.php">
  30.                 Logout
  31.             </a>
  32.         </header>
  33.         <h1>
  34.             Mails
  35.         </h1>
  36.         <!-- Display Button -->
  37.         <form method="get" class="Select">
  38.             <input type="submit" value="Display" id="Select" name="Select" />
  39.         </form>
  40.         <!-- Mail Table -->
  41.         <div class="Mails">
  42.             <table>
  43.                 <tr>
  44.                     <th id="MailID">
  45.                         ID
  46.                     </th>
  47.                     <th id="MailName">
  48.                         Name
  49.                     </th>
  50.                     <th id="MailEmail">
  51.                         Email
  52.                     </th>
  53.                     <th id="MailMessage">
  54.                         Message
  55.                     </th>
  56.                 </tr>
  57.                 <?php
  58.                 if (isset($_GET['Select'])) {
  59.                     // Instantiating Stormy Systems class
  60.                     $StormySystems = new StormySystems();
  61.                     // The query that will verify if there is any mail in the Mail table.
  62.                     $MailQuery = "SELECT * FROM mail";
  63.                     $Statement = $StormySystems->Query($MailQuery);
  64.                     // Executing the query
  65.                     $StormySystems->Execute();
  66.                     // Retrieving the query's answer in the Mail Result variable.
  67.                     $MailResult = $StormySystems->ResultSet();
  68.                     // Displaying every row by using a for-each loop.
  69.                     foreach ($MailResult as $Row) {
  70.                         echo "<tr><td>" . $Row['MailID'] . "</td><td>" . $Row['MailName'] . "</td><td>" . $Row['MailEmail'] . "</td><td>" . $Row['MailMessage'] . "</td></tr>";
  71.                     }
  72.                 }
  73.                 ?>
  74.             </table>
  75.         </div>
  76.         <!-- Form to delete mails from the database -->
  77.         <div class="DeleteForm">
  78.             <form method="post" class="Delete">
  79.                 <!-- Guide -->
  80.                 <h2>
  81.                     Deletion form
  82.                 </h2>
  83.                 <p>
  84.                     Use this form to make changes to the database!
  85.                 </p>
  86.                 <input type="text" name="ID" id="ID" placeholder="Enter the Mail ID to be deleted">
  87.                 <input type="submit" value="Delete" id="Delete" name="Delete" />
  88.                 <?php
  89.                 // Delete class which will retrive the values from the Delete post for be handled.
  90.                 class Delete {
  91.                     // ID Accessor Method
  92.                     function getID() {
  93.                         return $_POST['ID'];
  94.                     }
  95.                 }
  96.                 if (isset($_POST['Delete'])) {
  97.                     // Instantiating Delete class
  98.                     $Mail = new Delete();
  99.                     $MailID = $Mail->getID();
  100.                     // Instantiating Stormy Systems class
  101.                     $StormySystems = new StormySystems();
  102.                     // The query that will delete the mail which is associated to the value entered.
  103.                     $MailDeleteQuery = "DELETE FROM mail WHERE MailID = :MailID";
  104.                     $Statement = $StormySystems->Query($MailDeleteQuery);
  105.                     // Binding all the values
  106.                     $StormySystems->bind(":MailID", $MailID);
  107.                     // Executing the query
  108.                     $StormySystems->Execute();
  109.                 }
  110.                 ?>
  111.             </form>
  112.         </div>
  113.     </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement