Advertisement
Guest User

index.php

a guest
Mar 13th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.99 KB | None | 0 0
  1. <!--PHP variable for active nav link-->
  2. <?php $pageName = "Home"; ?>
  3. <!--PHP include statement for header-->
  4. <?php
  5.   include 'includes/header.php';
  6.  ?>
  7.     <div class="container">
  8.       <div class="page-header">
  9.         <h1>Home</h1>
  10.       </div>
  11.     </div>
  12.     <div class="container">
  13.         <div class="row">
  14.           <!--Posts-->
  15.           <div class="col-md-8">
  16.             <!--Title-->
  17.             <?php
  18.               $servername = "localhost";
  19.               $username = "root";
  20.               $password = "bangalore";
  21.               $dbname = "cms";
  22.  
  23.               // Create connection
  24.               $conn = new mysqli($servername, $username, $password, $dbname);
  25.               // Check connection
  26.               if ($conn->connect_error) {
  27.                   die("Connection failed: " . $conn->connect_error);
  28.               }
  29.  
  30.               $sql = "SELECT * FROM posts WHERE post_status=\"Published\"";
  31.               $result = $conn->query($sql);
  32.  
  33.               if ($result->num_rows > 0) {
  34.                   // output data of each row
  35.                   while($row = $result->fetch_assoc()) {
  36.                     $showPostID = $row['post_id'];
  37.                     echo "<a href=\"http://localhost/A3/posts.php?showPostID=$showPostID\"><h3 class=\"cover-heading\">Post Title: " . $row['post_title'] .  "</h3></a>";
  38.                     echo "<a href=\"#\"><p>Author: " . $row['post_author'] . "</p></a>";
  39.                     echo "<p>Date: " . $row['post_date'] . "</p>";
  40.                     echo "<p>" . $row['post_content'] . "</p>";
  41.                     echo "<br><br><hr>";
  42.                   }
  43.               } else {
  44.                   echo "0 results";
  45.               }
  46.               $conn->close();
  47.             ?>
  48.           </div>
  49.           <!--Login and report issue functionalities-->
  50.           <div class="col-md-4">
  51.             <div class="jumbotron">
  52.               <div class="header">
  53.                 <h3>Login</h3>
  54.               </div>
  55.               <?php
  56.               echo "<form method=\"post\" action=\"" . basename($_SERVER['PHP_SELF']) . "\">"
  57.               ?>
  58.                 <div class="form-group">
  59.                   <label>Username</label>
  60.                   <input type="text" name="username" class="form-control" placeholder="Username" required>
  61.                 </div>
  62.                 <div class="form-group">
  63.                  <label for="exampleInputPassword1">Password</label>
  64.                  <input type="password" name="password" class="form-control" placeholder="Password" required>
  65.                 </div>
  66.                 <button type="submit" name="Login" class="btn btn-primary center-block" >Login</button><br>
  67.                 <a href="#"><p class="text-center">forget password</p></a>
  68.               </form>
  69.             </div>
  70.             <!--Error report panel-->
  71.             <div class="jumbotron">
  72.               <div class="header">
  73.                 <h3>Report Issue</h3>
  74.               </div>
  75.               <?php
  76.               echo "<form method=\"post\" action=\"" . basename($_SERVER['PHP_SELF']) . "\">"
  77.               ?>
  78.                 <div class="form-group">
  79.                   <label>Name</label>
  80.                   <input type="text" name="name" class="form-control" placeholder="Preferred Name" required>
  81.                 </div>
  82.                 <div class="form-group">
  83.                   <label>Email address</label>
  84.                   <input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="E-mail" required>
  85.                 </div>
  86.                 <div class="form-group">
  87.                   <label for="sel1">Select Issue Type</label>
  88.                   <select name="sel1" class="form-control" id="sel1">
  89.                     <option value="Link not working">Link not working</option>
  90.                     <option value="Page not Found">Page not Found</option>
  91.                     <option value="Incorrect script">Incorrect script</option>
  92.                   </select>
  93.                 </div>
  94.                 <div class="form-group">
  95.                   <label for="message">Message:</label>
  96.                   <textarea class="form-control" name="message" rows="5" id="message" required></textarea>
  97.                 </div>
  98.                 <button type="submit" name="Submit" class="btn btn-success" value="Submit">Submit</button>
  99.                 <button type="reset" class="btn btn-info" value="Reset">Reset</button>
  100.               </form>
  101.               <?php
  102.                 date_default_timezone_set("America/Halifax");
  103.                 $datestuff = date("h.i.s") . "-" . date("Y.m.d");
  104.                 $name = "";
  105.                 $email = "";
  106.                 $message = "";
  107.                 $errorType = "";
  108.  
  109.                 if(isset($_POST['Submit'])) {
  110.                   $report = fopen("misc/message_" . $datestuff . ".txt", "w") or die("Unable to open file!");
  111.                   $name = validate_form_data($_POST['name']);
  112.                   $email = validate_form_data($_POST['email']);
  113.                   $message = validate_form_data($_POST['message']);
  114.                   $alertType = validate_form_data($_POST['sel1']);
  115.                   fwrite($report, "Issue Alert!\r\n");
  116.                   fwrite($report, "Type of issue: " . $alertType . "\r\n\r\n");
  117.                   fwrite($report, "Submitted by: " . $name . "\r\n");
  118.                   fwrite($report, "Email ID: " . $email . "\r\n");
  119.                   fwrite($report, "Submitted at: " . date("h:i:sa") . " on " . date("Y-M-d") . "\r\n\r\n");
  120.                   fwrite($report, "Details: " . $message);
  121.                   fclose($report);
  122.                 }
  123.  
  124.                 function validate_form_data($formdata){
  125.                   $formdata = trim($formdata);
  126.                   $formdata = stripslashes($formdata);
  127.                   $formdata = htmlspecialchars($formdata);
  128.                   return $formdata;
  129.                 }
  130.               ?>
  131.             </div>
  132.           </div>
  133.         </div>
  134.     </div><!-- /.container -->
  135. <?php
  136.   include 'includes/footer.php';
  137.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement