Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php
  2.     $action = $_REQUEST["action"];
  3.     $target = $_REQUEST["target"];
  4.     $srctitle = $_POST["srctitle"];
  5.     $title = $_POST["article_title"];
  6.     $cat = $_POST["article_cat"];
  7.     $content = $_POST["article_content"];
  8.    
  9.     // Set database server access variables:
  10.     $host = "localhost";
  11.     $user = "root";
  12.     $pass = "root";
  13.     $db = "logansarchive";
  14.  
  15.     // Open connection
  16.     $dbh = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pass);  
  17.    
  18.     $date = date('Y-m-d H:i:s');
  19.     switch ($action) {
  20.         case "Edit":
  21.             $query = $dbh->prepare("UPDATE Articles ".
  22.                 "SET ArticleTitle = :title, Category = :cat, ArticleDate = :date, ArticleContent = :content ".
  23.                 "WHERE ArticleTitle = :srctitle");
  24.             $query->bindParam(':title', $title);
  25.             $query->bindParam(':cat', $cat);
  26.             $query->bindParam(':date', $date);
  27.             $query->bindParam(':content', $content);
  28.             $query->bindParam(':srctitle', $srctitle);
  29.             $query->execute();
  30.         break;
  31.         case "New":
  32.             $query = $dbh->prepare("INSERT INTO Articles(Category, ArticleDate, ArticleTitle, ArticleContent) ".
  33.                 "VALUES(:cat, :date, :title, :content)");
  34.             $query->bindParam(':cat', $cat);
  35.             $query->bindParam(':date', $date);
  36.             $query->bindParam(':title', $title);
  37.             $query->bindParam(':content', $content);
  38.             $query->execute();
  39.         break;
  40.         case "Delete":
  41.             if ($target != "") {
  42.                 $query = $dbh->prepare("UPDATE Articles ".
  43.                     "SET DeletedYN = :del ".
  44.                     "WHERE ArticleTitle = :title");
  45.                 $query->bindValue(':del', "Yes");
  46.                 $query->bindParam(':title', $target);
  47.                 $query->execute();
  48.             }
  49.             else {
  50.                 header("Location: index.php?result=failed");
  51.             }
  52.         break;
  53.     }
  54.    
  55.     header("Location: index.php?result=success");
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement