daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5.  
  6. $host = 'localhost';
  7. $db = 'addnews';
  8. $user = 'root';
  9. $pass = '';
  10. $charset = 'utf8';
  11. // $text = (isset($_POST['title']) && !empty($_POST['title']))?'%'.$_POST['title'].'%':'';
  12.  
  13. $title = $_POST['title'];
  14. $date = $_POST['date'];
  15. $status = $_POST['publish_in_index'];
  16. $category = $_POST['category'];
  17. $content = $_POST['content'];
  18. $author = $_POST['author'];
  19.  
  20. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  21.  
  22. $opt = [
  23.     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  24.     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  25.     PDO::ATTR_EMULATE_PREPARES   => false,
  26. ];
  27.  
  28. echo $title.'<br>';
  29. echo $date.'<br>';
  30. echo $status.'<br>';
  31. echo $category.'<br>';
  32. echo $content.'<br>';
  33. echo $author.'<br>';
  34. $pdo = new PDO($dsn, $user, $pass, $opt);
  35.  
  36. if(!empty($title) && !empty($content) && !empty($author)){
  37.     $sql = "INSERT INTO `news` (`title`, `publish_date`, `status`, `category`, `content`, `author`)
  38.             VALUES (:title, :publish_date, :status, :category, :content, :author)";
  39.  
  40.     $rows = $pdo->prepare($sql);
  41.     $rows->execute([
  42.             'title'=>$title,
  43.             'publish_date'=>$date,
  44.             'status'=>$status,
  45.             'category'=>$category,
  46.             'content'=>$content,
  47.             'author'=>$author
  48.         ]);
  49.  
  50.     echo "Запись добавлена";
  51. }else{
  52.     echo "Запись не добавлена";
  53. }
  54.  
  55. ?>
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