SHARE
TWEET

Untitled

a guest Oct 17th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. <?php
  5.  
  6. ini_set('display_errors', 1);
  7. ini_set('display_startup_errors', 1);
  8. error_reporting(E_ALL);
  9.  
  10. $dbName = 'blog';
  11. $dbHost = 'localhost';
  12. $dbUser = 'root';
  13. $dbPass = '';
  14.  
  15. ?>
  16.  
  17. <!DOCTYPE html>
  18. <html lang="en">
  19.   <head>
  20.     <meta charset="utf-8">
  21.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  22.     <meta name="viewport" content="width=device-width, initial-scale=1">
  23.     <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  24.     <title>Create Post</title>
  25.  
  26.     <!-- Bootstrap -->
  27.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  28.  
  29.     <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  30.     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  31.     <!--[if lt IE 9]>
  32.       <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  33.       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  34.     <![endif]-->
  35.   </head>
  36.   <body>
  37.     <div class="container">
  38.         <div class="row">
  39.             <div class="col-md-12">
  40.  
  41. <?php
  42.  
  43. if(isset($_POST['submit'])){
  44.  
  45.     $postTitle = $_POST['postTitle'];
  46.     $postSlug = "";
  47.     $postContent = $_POST['postContent'];
  48.     $postAuthorID = "1";
  49.     $postCategoryID = "1";
  50.     $postDate = date("Y-m-d");
  51.     $postActive = "1";
  52.  
  53. try {
  54. $db = new PDO( "mysql:dbname=$dbName;host=$dbHost" , $dbUser , $dbPass );
  55.  
  56. $sql = $db->prepare("INSERT INTO posts (postTitle, postSlug, postContent, postCategoryId, postAuthorId, postDate, postActive) VALUES (? ,? ,?, ?, ?, ?, ?)");
  57. $sql->bindParam(1, $postTitle);
  58. $sql->bindParam(2, $postSlug);
  59. $sql->bindParam(3, $postContent);
  60. $sql->bindParam(4, $postCategoryId);
  61. $sql->bindParam(5, $postAuthorId);
  62. $sql->bindParam(6, $postDate);
  63. $sql->bindParam(7, $postActive);
  64.  
  65. $sql->execute();
  66.  
  67. echo 'New Post entered';
  68.  
  69. } catch ( PDOException $e) {
  70.     echo $e->getMessage();
  71. }
  72. } else {
  73. ?>
  74.  
  75.  
  76. <h2>Create a new Post</h2>
  77. <form  action="create_post.php" method="post">
  78. <div class="input-group">
  79.   <span class="input-group-addon" id="basic-addon1">Post Title</span>
  80.   <input type="text" class="form-control" name="postTitle">
  81. </div>
  82. <br>
  83. <div class="input-group">
  84.   <span class="input-group-addon" id="basic-addon1">Post Content</span>
  85.   <textarea rows="10" class="form-control" name="postContent"></textarea>
  86. </div>
  87. <br>
  88. <div class="input-group">
  89.   <button type="submit" name="submit" class="btn btn-primary">Submit</button>
  90. </div>
  91.  
  92. <?php
  93. }
  94. ?>
  95.  
  96.             </div>
  97.         </div>
  98.     </div>    
  99.  
  100.     <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  101.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  102.     <!-- Include all compiled plugins (below), or include individual files as needed -->
  103.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  104.   </body>
  105. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top