1j0e

submitsuggestion.php

May 16th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. $userIP = $_SERVER['REMOTE_ADDR'];
  4. $longIP = ip2long($userIP);
  5. $content = $_POST["txtSuggestion"];
  6. $con = mysql_connect( "localhost","lolerman","root" );
  7. $postcount = 0;
  8. $duplicate = 0;
  9.  
  10. if ( !$con ){
  11.  
  12. die( 'Could not connect: ' . mysql_error() );
  13.  
  14. } else {
  15.  
  16. mysql_select_db( "lolerman_lolerstream", $con );
  17.  
  18. $query = "SELECT * FROM suggestions WHERE IP = $longIP";
  19.  
  20. $result1 = mysql_query( $query,$con ) or die( 'Could not execute query: ' . mysql_error() );
  21.  
  22. if ( mysql_num_rows( $result1 ) ) {
  23.  
  24. while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {
  25.  
  26. if (preg_replace('/\s+/', '', $content) != preg_replace('/\s+/', '', $row1['content'])) {
  27.  
  28. if (strtotime($row1['submitdate']) == strtotime(date("m/d/Y"))){
  29.  
  30. $postcount += 1;
  31.  
  32. }
  33.  
  34. } else {
  35.  
  36. $duplicate = 1;
  37. break;
  38.  
  39. }
  40.  
  41. }
  42.  
  43. }
  44.  
  45. if ($postcount < 3) {
  46.  
  47. if ($duplicate == 0){
  48.  
  49. $today = date("m/d/Y");
  50.  
  51. $query = "INSERT INTO suggestions (content, submitdate, IP) VALUES ('$content', '$today', $longIP)";
  52.  
  53. $result = mysql_query( $query,$con ) or die( 'Could not execute query: ' . mysql_error() );
  54.  
  55. //echo "<script type='text/javascript'>refreshsuggestions();</script>";
  56.  
  57. } else {
  58.  
  59. echo "<script type='text/javascript'>alert('You already suggested that.');</script>";
  60.  
  61. }
  62.  
  63. } else {
  64.  
  65. echo "<script type='text/javascript'>alert('You have exceeded your suggestion limit for the day.');</script>";
  66.  
  67. }
  68.  
  69. }
  70. mysql_close($con);
  71.  
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment