Advertisement
Strider64

Home Page PHP & HTML

Oct 12th, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.34 KB | None | 0 0
  1. <?php
  2. require_once 'lib/includes/config.php'; // Configuration file for turning error reporting and connection strings to database:
  3. require_once 'lib/functions/php_pdo_functions.inc.php'; // PDO functions and connection:
  4.  
  5. /*
  6.  * The first thing to do is to make sure you have a database named myCMS and a database table named myBlog.
  7.  * You can run the install file that will create the database and database table by running install.php if you want
  8.  * or you can create the database and database table yourself.
  9.  */
  10.  
  11.  
  12. /*
  13.  * Read from a database table is pretty straight forward and the only real tough part of it is writing the
  14.  * query correctly. Visting https://www.mysql.com/ will help you understand MySQl.
  15.  * PDO can better be understand by visiting https://phpdelusions.net/pdo and I highly recommend the website for it
  16.  * has helped me to understand pdo better. One word of advice and that is to ALWAYS use PREPARED statements for
  17.  * security reasons. I also recommend staying up on on PHP, PDO and MYSQL, for all tutorials will eventually become
  18.  * outdated (even this one). I have relocated all the pdo functions and connection over to php_pdo_functions.inc.php file.
  19.  */
  20.  
  21. /*
  22.  * Check to see if user has clicked on the submit button.
  23.  */
  24. $submit = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
  25.  
  26. if (isset($submit) && $submit === "submit") {
  27.     /*
  28.      * Grab User's Responses from Form.
  29.      */
  30.     $data['title'] = htmlspecialchars($_POST['title']);
  31.     $data['comment'] = htmlspecialchars($_POST['comment']);
  32.  
  33.     $result = createBlog($data, $pdo);
  34.  
  35.     if ($result) {
  36.         header("Location: index.php");
  37.         exit();
  38.     }
  39. }
  40.  
  41. $rows = readBlog($pdo);
  42. if (isset($_SESSION['user']) && $_SESSION['user']['security'] === 'public') {
  43.     $cmsON = TRUE;
  44. } else {
  45.     $cmsON = FALSE;
  46. }
  47. //echo "<pre>" . print_r($rows, 1) . "</pre>";
  48. ?>
  49. <!DOCTYPE html>
  50. <html lang="en">
  51.     <head>
  52.         <meta charset="UTF-8">
  53.         <meta name="viewport" content="initial-scale=1.0, width=device-width" />
  54.         <title>PHP, PDO &amp; MySQL Tutorial</title>
  55.         <!--
  56.         I decided to make an external stylesheet to keep the code down. The stylesheet stays in the same folder
  57.         as the other files. Feel free to use this file or create your own CSS.
  58.         -->
  59.         <link rel="stylesheet" href="lib/css/reset.css">
  60.         <link rel="stylesheet" href="lib/css/style.css">
  61.     </head>
  62.     <body>
  63.         <?php require_once 'lib/includes/heading.inc.php'; ?>
  64.         <div class="container bg-color">
  65.             <?php if ($cmsON) { ?>
  66.                 <form id="commentForm" action="" method="post">
  67.                     <fieldset>
  68.                         <legend>Comment Form</legend>
  69.                         <label for="title">Title</label>
  70.                         <input id="title" type="text" name="title" value="" autofocus  tabindex="1">
  71.                         <label class="textBox" for="comment">Comment</label>
  72.                         <textarea id="comment" name="comment" tabindex="2"></textarea>
  73.                         <input type="submit" name="submit" value="submit" tabindex="3">
  74.                     </fieldset>
  75.                 </form>
  76.             <?php } else { ?>
  77.             <div id="cmsInfo">
  78.                 <h1>PDO &amp; MySQL Tutorial Information</h1>
  79.                 <p>You must be registered and login to access the full Content Management System Demo. I'm writing this PHP Tutorial in procedural style with the exception of PDO which forces a person to write it in Object-Oriented Programming Style. This tutorial will show you how to add, update, read and delete content to a MySQL database using PHP PDO.</p>
  80.             </div>
  81.             <?php } ?>
  82.             <div id="articles">
  83.                 <?php
  84.                 foreach ($rows as $row) {
  85.                     echo '<div class="article">' . "\n";
  86.                     echo "<h2>" . $row['title'] . "</h2>\n";
  87.                     echo '<span class="date">' . $row['display_date'] . '</span>' . "\n";
  88.                     echo '<a class="anchor-tag" href="edit.php?id=' . $row['id'] . '">Edit</a>' . "\n";
  89.                     echo "<p>" . $row['comment'] . "</p>\n";
  90.                     echo "</div>\n";
  91.                 }
  92.                 ?>                              
  93.             </div>
  94.         </div>
  95.     </body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement