Advertisement
rhiby

shout box dengan database

Mar 28th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <title>shoutbox php version flazer</title>
  2. <?php
  3. //------ Edit Below This Line ------//
  4.  
  5. define('SHOUTBOX', 'shoutbox');
  6.  
  7. $host = 'localhost';
  8. $dbuser = 'homo'; // Username to access database.
  9. $dbpass = 'arshomo^)(^'; // Password to access database.
  10. $dbname = 'homo'; // Database name.
  11.  
  12. $allowed_tags = '<b><i><u><a>';
  13.  
  14. //------ Edit Above This Line ------//
  15.  
  16. mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
  17. mysql_select_db($dbname) or die(mysql_error());
  18.  
  19. function clean_string($string, $tags = '')
  20. {
  21. $string = trim($string);
  22. $string = str_replace("\'", "''", $string);
  23. return $string;
  24. }
  25.  
  26. ?>
  27. <style type="text/css">
  28. .shoutbox {
  29. margin: 0px;
  30. padding: 0px;}
  31.  
  32. .shoutbox a, a:visited {
  33. color: 6E7A8A;
  34. font-size: 12px;
  35. font-weight: bold;
  36. text-decoration: none;}
  37.  
  38. .shoutbox a:hover {
  39. color: 6E7A8A;
  40. text-decoration: underline;}
  41.  
  42. .shoutbox input, select, textarea {
  43. border: 1px solid silver;}
  44.  
  45. .form {
  46. font-size: 12px;}
  47.  
  48. #name1 {
  49. background-color: E0E0E0;
  50. color: 666666;
  51. font-size: 12px;}
  52. #content1 {
  53. background-color: E0E0E0;
  54. font-size: 12px;}
  55.  
  56. #name2 {
  57. background-color: F3F3F3;
  58. color: 666666;
  59. font-size: 12px;}
  60. #content2 {
  61. background-color: F3F3F3;
  62. font-size: 12px;}
  63. </style>
  64. <?php
  65.  
  66. switch($_GET['p'])
  67. {
  68. case 'box':
  69. echo "<body class=\"shoutbox\">\n<table cellpadding=\"2\">";
  70.  
  71. $result = mysql_query("SELECT * FROM " . SHOUTBOX . " ORDER BY id DESC") or die(mysql_error());
  72. for ($i = 1; $i <= ($row = mysql_fetch_assoc($result)); $i++)
  73. {
  74. $nameid = (!($i % 2)) ? 'name1' : 'name2';
  75. $contentid = (!($i % 2)) ? 'content1' : 'content2';
  76.  
  77. $name = strip_tags(stripslashes($row['name']), $allowed_tags);
  78. $website = strip_tags(stripslashes($row['website']), $allowed_tags);
  79. $content = strip_tags(stripslashes($row['content']), $allowed_tags);
  80.  
  81. echo '<tr><td id="' . $nameid . '" width="50" align="right">',
  82. ((!empty($row['website'])) ? "<a href=\"$website\">$name</a>" : $name),
  83. '</td><td id="' . $contentid . '" width="170">' . $content . "</td></tr>\n";
  84. }
  85.  
  86. echo "</table>\n</body>";
  87. break;
  88.  
  89. default:
  90. echo '<div class="shoutbox">';
  91.  
  92. if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['name']) && !empty($_POST['content']))
  93. {
  94. $name = clean_string($_POST['name']);
  95. $website = clean_string($_POST['website']);
  96. $website = (!empty($website) && $website != 'http://') ? (!eregi('^http://', $website) ? 'http://' . $website : $website) : '';
  97. $content = nl2br(clean_string($_POST['content'], '<a>'));
  98.  
  99. mysql_query("INSERT INTO " . SHOUTBOX . " (name, website, content) VALUES ('$name', '$website', '$content')") or die(mysql_error());
  100. }
  101.  
  102. echo '<iframe src="' . basename($_SERVER['PHP_SELF']) . '?p=box" width="260" height="285"></iframe>
  103. <form method="post"><table class="form">
  104. <tr><td align="right">Name:</td><td><input type="text" name="name" size="10"></td></tr>
  105. <tr><td align="right">Website:</td><td><input type="text" name="website" value="http://" size="10"></td></tr>
  106. <tr><td align="right">Message:</td><td><textarea name="content" rows="3" cols="20"></textarea></td></tr>
  107. <tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
  108. </table></form>', "\n</div>";
  109. break;
  110. }
  111.  
  112.  
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement