Ostap34JS

Posts_edit_funvtion

Feb 24th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.71 KB | None | 0 0
  1. <?php
  2.                 if($_GET['post_id']){
  3.                     $get_id = $_GET['post_id'];
  4.  
  5.  
  6.                     $get_post = "select * from `posts` where post_id='$get_id'";
  7.                     $run_post = mysqli_query($con,$get_post);
  8.                     $row = mysqli_fetch_array($run_post);
  9.  
  10.                     if($row['user_id'] == $user_id){
  11.                         $post_title = $row['post_title'];
  12.                         $post_content = $row['post_content'];
  13.                     }
  14.                     else{
  15.                         die("<s>}{@керам тут не місце!</s><h1>Відмовлено в доступі...</h1>");
  16.                     }
  17.  
  18.                 }
  19.                 ?>
  20.                 <form action="" method="post" onsubmit="texarea()">
  21.                     <h2>Редагувати допис:</h2><br>
  22.                     <input type="text" value="<?=$post_title?>" name="title" class="form_control" id="title_text" placeholder="Введіть заголовок">
  23.                     <button class="btn_smiles" id="btn_smiles"></button>
  24.  
  25.                     <input type="text" name="content" id="textarea"/>
  26.                     <select name="topic" class="form_control" required>
  27.                         <option>Виберіть тему</option>
  28.                         <?php getTopics(); ?>
  29.                     </select>    
  30.                     <button name="update" class="btn">Редагувати допис</button>
  31.                 </form>
  32.                 <?php
  33.                 if(isset($_POST['update'])){
  34.                     $title = $_POST['title'];
  35.                     $content = $_POST['content'];
  36.  
  37.                     if(!$title){
  38.                         echo"Прблема з title!";
  39.                     }
  40.                     if(!$content){
  41.                         echo"Прблема з content!";
  42.                     }
  43.  
  44.                     $update_post = "update `posts` set post_title='$post_title' where post_id='$get_id'";
  45.                     $run_post = mysqli_query($con,$update_post);
  46.  
  47.                     if(!$run_post){
  48.                         echo"Прблема з run_post!";
  49.                     }
  50.  
  51.  
  52.                     if($run_post){
  53.                         echo"<script>alert('Ваш пост оновлено!');</script>";
  54.                         //                        echo"<script>window.open('home.php','_self');</script>";
  55.                     }
  56.                     else{
  57.                         echo"<script>alert('Ваш пост НЕ оновлено...');</script>";
  58.                         //                        echo"<script>window.open('home.php','_self');</script>";
  59.                     }
  60.                 }
  61.                 ?>
Advertisement
Add Comment
Please, Sign In to add comment