SHARE
TWEET

Untitled

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