Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.32 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include 'dbconfig.php';
  4.  
  5. if($_POST[skapa]) {
  6.  
  7. $title = htmlspecialchars($_POST['title']);
  8. $pretext = htmlspecialchars($_POST['pretext']);
  9. $text = htmlspecialchars($_POST['text']);
  10. $img = htmlspecialchars($_POST['img']);
  11. $date = date("y-n-d");
  12. $uid =  $_SESSION["user_id"];
  13.  
  14. $update = mysql_query("UPDATE news SET title = '$title', pretext = '$pretext', text = '$text', date ='$date', uid ='$uid', img = '$img' WHERE id = '$id' LIMIT 1");
  15.  
  16. }
  17.  
  18. if (isset($_GET['mer'])) {
  19. $id = $_GET['mer'];
  20.  
  21. $sql = mysql_query("
  22. SELECT *, news.id AS newsid
  23. FROM news
  24. JOIN users ON (users.id=news.uid)
  25. WHERE news.id = '$id' LIMIT 1") or die(mysql_error());
  26.  
  27. while($news = mysql_fetch_array($sql))
  28. echo '<div class="article">
  29.                 <div class="story">
  30.                     <h4 class="title">'.$news['title'].'</h4>  
  31.                     '.$news['text'].'
  32.                 </div>
  33.                 <div class="more">
  34.                     <div class="author-image"><img src="'.$news['avatar'].'" alt="Agressions" /></div>
  35. <span class="post-date">'.$news['name'].'<br /> '.$news['date'].'</span>
  36. <ul>                        <li><a href="?mer='.$news['newsid'].'" class="kommentera" title="Läs hela artikeln" style="margin-bottom:10px;">Kommentera</a></li></ul>
  37.                 </div>
  38.             </div>';
  39.             }
  40. if (isset($_GET['news-edit'])) {
  41. $id = $_GET['news-edit'];
  42.  
  43. $sql = mysql_query("
  44. SELECT *, news.id AS newsid
  45. FROM news
  46. JOIN users ON (users.id=news.uid)
  47. WHERE news.id = '$id' LIMIT 1") or die(mysql_error());
  48.  
  49. while($news = mysql_fetch_array($sql))
  50. echo '<div class="article2">   
  51.                 <div class="story2">
  52.                     <h4 class="title">Ändring av '.$news['title'].'</h4>  
  53.                     <p><form method="post">Titel: <br /><input name="title" type="text" value="'.$news['title'].'"><br />
  54.                     Bild: <br /><input name="img" type="text" value="'.$news['img'].'"><br />
  55.                        Inledande Text: <br /><textarea rows="10" cols="80" name="pretext">'.$news['pretext'].'</textarea><br />
  56.                        Texten: <br /><textarea rows="10" cols="80" name="text">'.$news['text'].'</textarea></p>
  57.                        <input type="submit" value="update" class="login" name="update" />
  58.                        </form>
  59.                 </div>
  60.             </div>';
  61.             if($_POST[update]) {
  62. $title = htmlspecialchars($_POST['title']);
  63. $pretext = htmlspecialchars($_POST['pretext']);
  64. $text = htmlspecialchars($_POST['text']);
  65. $img = htmlspecialchars($_POST['img']);
  66. $date = date("y-n-d");
  67. $uid =  $_SESSION["user_id"];
  68. $update = mysql_query("UPDATE news SET title = '$title', pretext = '$pretext', text = '$text', date ='$date', uid ='$uid', img = '$img' WHERE id = '$id' LIMIT 1");
  69.  
  70. }
  71.             }
  72. else {
  73. $sql = mysql_query("
  74. SELECT *, news.id AS newsid
  75. FROM news
  76. JOIN users ON (users.id=news.uid)
  77. ORDER by news.id desc") or die(mysql_error());
  78.  
  79. while($news = mysql_fetch_array($sql))
  80. echo '<div class="article">
  81.                 <div class="story">
  82.                     <h4 class="title">'.$news['title'].'</h4>  
  83.                     '.$news['text'].'
  84.                 </div>
  85.                 <div class="more">
  86.                     <div class="author-image"><img src="'.$news['avatar'].'" alt="Agressions" /></div>
  87.                     <span class="post-date">'.$news['name'].'<br /> '.$news['date'].'</span>
  88.                     <ul>
  89.                         <li><a href="?mer='.$news['newsid'].'" class="kommentera" title="Läs hela artikeln">Läs allt</a></li>
  90.                         <li><a href="?mer='.$news['newsid'].'" class="kommentera" title="Läs hela artikeln" style="margin-bottom:10px;">Kommentera</a></li>
  91.                     </ul>
  92.                 </div>
  93.             </div>';
  94. }                  
  95.             ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement