Advertisement
Nikita051

Untitled

Sep 14th, 2022
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     $local = "localhost";
  4.     $login = "root";
  5.     $pass = "root";
  6.     $name = "forum";
  7.     $link = mysqli_connect($local,$login,$pass,$name);
  8.    
  9.     $slug = $params['topicSlug'];
  10.     $topic = str_replace("-",' ',$slug);
  11.     if(!empty($_POST['title']) && !empty($_POST['content'])){
  12.         $title = $_POST['title'];
  13.         $content = $_POST['content'];
  14.         if(preg_match("#[a-zA-Z_-]{0,30}#",$title)){
  15.             $query = mysqli_query($link,"SELECT * FROM fast WHERE title='$title'");
  16.             $test = mysqli_fetch_assoc($query);
  17.             if(empty($test)){
  18.                 $fastSlug = $title;
  19.                 $fastSlug = str_replace(" ","-",$fastSlug);
  20.                 $query = mysqli_query($link,"SELECT * FROM topics WHERE topic_name = '$topic'");
  21.                 $res = mysqli_fetch_assoc($query);
  22.                 $topic_id = $res['id'];
  23.                 $query = mysqli_query($link,"INSERT INTO fast SET slug='$fastSlug',title='$title',content = '$content',topic_id='$topic_id'");
  24.             }
  25.         }  
  26.     }
  27.  
  28.    
  29.     if($_SESSION['auto'] === true){
  30.         $query = mysqli_query($link,"SELECT * FROM fast
  31.            LEFT JOIN topics ON topics.id = fast.topic_id
  32.            WHERE topic_name = '$topic'") or die(mysqli_error($link));
  33.             $data = [];
  34.             while($row = mysqli_fetch_assoc($query)){
  35.                 $data[] = $row;
  36.             };
  37.             $content = '';
  38.             foreach($data as $value){
  39.                 $content .= "<a href='/main/".$slug."/".$value['title']."'>".$value['title']."</a></br>";
  40.             }
  41.             $page = [
  42.                 'title' => 'wall',
  43.                 'content' => $content
  44.             ];
  45. ?>
  46. <form action="" method="POST">
  47.     <input name="title" placeholder="Title"></br>
  48.     <textarea name="content"></textarea></br>
  49.     <input type='submit'></br>    
  50. </form>
  51. <?php
  52.             return $page;
  53.         } else {
  54.             header("Location: /auto");
  55.         }
  56. ?>
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement