Posted By

DrPepper on 05/24/11


Tagged


Versions (?)

current blog code


 / Published in: PHP
 

  1. /*####
  2. master.php
  3. ####*/
  4.  
  5. if(isset($userName) and isset($passWord))
  6. {
  7. if(($userName==$user) and ($passWord==$pass))
  8. {
  9. ?>
  10. <form method='post' action='blog_post.php'>
  11. Subject : <input name='subject' type='text' /><br />
  12. Contents :<br />
  13. <textarea name='contents' rows='20' cols='100'>
  14. </textarea>
  15. <br />
  16. <button class="textArea" type='submit'>Post</button>
  17. </form></center>
  18. <?php
  19. }
  20. else
  21. {
  22. ?><font color="red">*User name or passwrd is not mach as the database. <br />
  23. Please try again </font>
  24. <form method='post' action='master.php'>
  25. User Name : <input name='user' type='text' /><br />
  26. Pass World : <input name='passwd' type='text' /><br />
  27. <button class="textArea" type='submit'>Login</button>
  28. </form>
  29. <?php
  30. }
  31. }
  32. else
  33. {
  34. ?>
  35. <form method='post' action='master.php'>
  36. User Name : <input name='user' type='text' /><br />
  37. Pass World : <input name='passwd' type='text' /><br />
  38. <button class="textArea" type='submit'>Login</button>
  39. </form>
  40. <?php
  41. }
  42. ?>
  43.  
  44. /*#######
  45. blog_post.php
  46. #######*/
  47.  
  48. <?php
  49. $article = str_replace("\n", "<br />",$article);
  50. $query="INSERT INTO rksb_weblog(title,article,posterID,isMain,branch) VALUES('$subject','$article','$posterID', '$isMain', '$branch')";
  51. mysql_query($query);
  52.  
  53. ?>
  54.  
  55. /*######
  56. blog.php
  57. ######*/
  58.  
  59. mysql_select_db($database);
  60.  
  61. function select ($page, $perpage) {
  62. $query = "SELECT id,".
  63. " title,".
  64. " article,".
  65. " posterID,".
  66. " isMain,".
  67. " branch,".
  68. " DATE_FORMAT(postDate, '%r %d-%m-%Y') as postDate".
  69. " FROM rksb_weblog".
  70. " ORDER BY postDate".
  71. " LIMIT $page, $perpage";
  72. return mysql_query($query);
  73. }
  74.  
  75. if (isset($_GET['page']))
  76. { $page = $_GET['page']; $counter=+$page; }
  77. else
  78. { $page = 0; $counter=0; }
  79. $page *= $perpage;
  80. $result = select($page, $perpage);
  81. while($row = mysql_fetch_assoc($result))
  82. {
  83. echo "<h3>".$row['title']." ".$row['postDate']."</h3><br />".
  84. "<p>".$row['article'] ."</p><br />".
  85. "<br />".
  86. "<a href='./blog.php?id=comment&comID=".$counter."'>".
  87. "COMMENT(0)</a>";
  88. }/*
  89. if(!$row)
  90. {
  91. echo "<h3>There is no article ....</h3><br />".
  92. "<p>I am really sorry tho...<br />".
  93. "I haven't posted any blog article <br />".
  94. "Please try to come here any other day ... <br />".
  95. "Thank you for your visiting today !! </p><br />";
  96. }*/
  97. ?>
  98.  
  99. /*#####
  100. data base
  101. #####*/
  102.  
  103. if (!$con)
  104. { die('Could not connect: ' . mysql_error()); }
  105. else
  106. { print "Connected to server "; }
  107.  
  108. // create data
  109. mysql_select_db("mysql_db", $con);
  110.  
  111. //when you want delete the table, comment out
  112. mysql_query("DROP TABLE rksb_weblog");
  113.  
  114. // when you wanna crerate table, comment out
  115. $query =
  116. "CREATE TABLE rksb_weblog".
  117. " (id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,".
  118. " title VARCHAR(100) NOT NULL,".
  119. " article LONGTEXT NOT NULL,".
  120. " posterID INT NOT NULL,".
  121. " isMain TINYINT NOT NULL,".
  122. " branch INT NOT NULL,".
  123. " postDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE".
  124. " CURRENT_TIMESTAMP)";
  125. mysql_query($query);
  126. if(!$query)
  127. { print "table was not created ".mysql_error(); }
  128. else
  129. { print "table has created "; }
  130. mysql_query($sql,$con);

Report this snippet  

You need to login to post a comment.