Your Ad Here

Posted By

Joekinglord on 12/26/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nerdfiles


shout.php


 / Published in: PHP
 

  1. <?php
  2.  
  3. $self = $_SERVER['PHP_SELF']; //the $self variable equals this file
  4. $ipaddress = ("$_SERVER[REMOTE_ADDR]"); //the $ipaddress var equals users IP
  5.  
  6. include ('connect.php'); // for db details
  7.  
  8. if(isset($_POST['send'])) {
  9.  
  10. if(isset($_COOKIE['user']) && strlen($_COOKIE['user']) > 1) {
  11. $name = $_COOKIE['user'];
  12. }
  13. else {
  14. $name = 'Guest';
  15. }
  16.  
  17. if(empty($_POST['post'])) {
  18. echo('<p class="error">You did not enter a post.</p>');
  19. } else {
  20. $post = htmlspecialchars(mysql_real_escape_string($_POST['post']));
  21.  
  22. $sql = "INSERT INTO shouts SET name='$name', post='$post', ipaddress='$ipaddress';";
  23.  
  24. if (@mysql_query($sql)) {
  25. echo('<p class="success">Thanks for shouting!</p>');
  26. } else {
  27. echo('<p class="error">There was an unexpected error when submitting your shout.</p>');
  28. }
  29. }
  30. }
  31.  
  32. $query = "SELECT * FROM `shouts` ORDER BY `id` DESC LIMIT 50;";
  33.  
  34. $result = @mysql_query($query) or die('<p class="error">There was an unexpected error grabbing shouts from the database.</p>');
  35.  
  36. while ($row = mysql_fetch_array($result)) {
  37.  
  38. $epost = stripslashes($row['post']);
  39.  
  40. echo('<div style="color: #00FFFF; float: left; padding-right: 5px;">'
  41. .$row['name'].':</div>');
  42. echo('<div class="post">'.$epost.'</div><hr />');
  43. }
  44. ?>
  45.  
  46. <form action="<?php $self ?>" method="post">
  47. <h4 style="padding: 0; margin: 1px;">Shoutbox</h4>
  48. <input name="send" type="hidden" />
  49. <input type="submit" value="Shout" />
  50. <h5 style="padding: 0; margin: 1px; color: #778899;">Shout:</h5><textarea name="post" cols="25" rows="1"></textarea>
  51. </form>

Report this snippet  

You need to login to post a comment.