SHARE
TWEET

Untitled

a guest Dec 8th, 2019 148 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HTML:
  2.  
  3.  <form method="post">
  4.          <div class="form-group">
  5.          <input type="text" class="form-control" placeholder="Ваше Имя:" name="name" required><br>
  6.          <textarea class="form-control" rows="3" name="text" required></textarea>
  7.          </div>
  8.          <button type="submit" class="btn btn-primary" name="submit">Отправить</button>
  9.          </form>
  10.  
  11. PHP:
  12.  
  13. //Добавление комментария к статье
  14. function add_comment($connect){
  15.     $post_id = (int)$_GET['post_id'];
  16.     if(isset($_POST['submit'])){
  17.         $name = trim(htmlspecialchars(mysqli_real_escape_string($connect, $_POST['name'])));
  18.         $text = trim(htmlspecialchars(mysqli_real_escape_string($connect, $_POST['text'])));
  19.         $sql = "INSERT INTO comments (`name`, `text`, `post_id`) VALUES ('$name', '$text', '$post_id')";
  20.         $result = mysqli_query($connect, $sql);
  21.         header("Location: ". $_SERVER["REQUEST_URI"]);
  22.     }
  23. }
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