Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

AJAX ERROR?

By: a guest on Mar 5th, 2012  |  syntax: None  |  size: 5.86 KB  |  views: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* chatlog.php */
  2.  
  3. <?php
  4. session_start();
  5.  
  6. include "connect.php";
  7.  
  8. $room = $_SESSION['room'];
  9. $getnummessages="SELECT COUNT(*) as messagecount from tbl_chatmessages";
  10. $getnummessages2=mysql_query($getnummessages) or die("blah");
  11. $getnummessages3=mysql_result($getnummessages2, 0);
  12.  
  13. if($getnummessages3>21)
  14.         {
  15.                 $startrow=$getmessages3-20;
  16.         }
  17. else
  18.         {
  19.                 $startrow=1;
  20.         }
  21.  
  22. date_default_timezone_set ("Asia/Manila");
  23.                         $date = date("Y-m-d");
  24.  
  25. $getmsg="SELECT * from tbl_chatmessages a, jcow_accounts b WHERE a.room_number='$room' && b.username=a.user_alias && a.date='$date' ORDER BY postime DESC";
  26. $getmsg2=mysql_query($getmsg) or die(mysql_error());
  27.  
  28. while($getmsg3=mysql_fetch_array($getmsg2))
  29.         {
  30.                 $message=Smiley($message); //Smiley faces
  31.  
  32. print "<div id='loaddiv'><div id='tablechatter'><table name='tablechat' id='tablechat' cellspacing='0' cellpadding='0' style='margin-top:10px;margin-left:0px;padding:0px;'>";
  33.                 print "<tr><td rowspan='2'><a href='index.php?p=u/$getmsg3[user_alias]' target='_blank'><img src='http://www.pinoyarea.com/uploads/avatars/$getmsg3[avatar]' width='50px' height='50px'/></td><td><font color='#333333' style='text-decoration:none;font-size:14px;font-family:tahoma;'><b>&nbsp;$getmsg3[name]</b></font></a> <font color='#666666' style='text-decoration:none;font-size:10px;font-family:tahoma;'>($getmsg3[time]):</font></td></tr><tr><td><font style='font-family:tahoma;font-size:12px;'>&nbsp;$getmsg3[message]</font></td></tr>";
  34. print "</table>";      
  35. print "</div>";
  36. }
  37.        
  38. function Smiley ($texttoreplace)
  39.         {
  40.                 $smilies = array
  41.                 (
  42.                         ':)' => "<img src='images/smile.gif'>",
  43.                         ':blush' => "<img src='images/blush.gif'>",
  44.                         ':angry' => "<img src='images/angry.gif'>",
  45.                         ':o' => "<img src='images/shocked.gif'>",
  46.                         'fuck' => "$#$%",
  47.                         'Fuck' => "&$#@",
  48.                         'bitch' => "$#%@&"
  49.                 );
  50.                
  51.                 $texttoreplace=str_replace(array_keys($smilies),array_values($smilies),$texttoreplace);
  52.                 return $texttoreplace;
  53.         }
  54.  
  55.  
  56.  
  57.  
  58. ?>
  59. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  60. <script>
  61. $.ajaxSetup({ datatype: "html" });
  62. var auto_refresh = setInterval(
  63. function()
  64. {
  65. $('#loaddiv').load('chatlog.php?alt=json-in-script&callback=?');
  66. }, 5000);
  67. </script>
  68.  
  69.  
  70.  
  71. /* submit.php */
  72.  
  73. <?php
  74. //if(isset($_POST['submit'])) //if submit button push has been detected
  75. //{
  76.         session_start();
  77.         include "connect.php";
  78.         $message=$_POST['message'];
  79.         $name = $_SESSION['username'];
  80.     $room = $_SESSION['room'];
  81.     $user = $_SESSION['user'];
  82.        
  83. $sql_row = mysql_query("SELECT * FROM tbl_chatmessages ORDER BY postime DESC");
  84. $count_row = mysql_num_rows($sql_row);
  85.         if(strlen($message)<1)
  86.                 {
  87.                         //print "<//script>alert('You did not input a message');<//script>";
  88.                 }
  89.         else if(strlen($name)<1)
  90.                 {
  91.                         //print "<script>alert('You did not enter a name, please try again.');<//script>";
  92.                 }
  93.     else if($count_row >= 50)
  94.                 {
  95.                 mysql_query("DELETE FROM tbl_chatmessages ORDER BY postime ASC LIMIT 1");
  96.  
  97.                 date_default_timezone_set ("Asia/Manila");
  98.                 $date = date("Y-m-d");
  99.                 $time = date("H:i:s");
  100.                 $real_time = DATE("g:i a", STRTOTIME($time));
  101.             $message=strip_tags($message);
  102.                         $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP
  103.                 $id=rand(11111111111111111111,99999999999999999999);
  104.                         $thedate=date("U"); //grab date and time of the post
  105.                         $insertmessage="INSERT into tbl_chatmessages (id,name,ip,postime,date,time,message,room_number,user_alias) VALUES ('$id','$name','$IP','$thedate', '$date' , '$real_time' ,'$message','$room','$user')";
  106.                         mysql_query($insertmessage) or die("Could not insert message");
  107.                 }
  108.         else
  109.                 {
  110.             date_default_timezone_set ("Asia/Manila");
  111.             $date = date("Y-m-d");
  112.             $time = date("H:i:s");
  113.             $real_time = DATE("g:i a", STRTOTIME($time));
  114.             $message=strip_tags($message);
  115.                         $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP
  116.             $id=rand(11111111111111111111,99999999999999999999);
  117.                         $thedate=date("U"); //grab date and time of the post
  118.                         $insertmessage="INSERT into tbl_chatmessages (id,name,ip,postime,date,time,message,room_number,user_alias) VALUES ('$id','$name','$IP','$thedate', '$date' , '$real_time' ,'$message','$room','$user')";
  119.                         mysql_query($insertmessage) or die("Could not insert message");
  120.                 }
  121. //}
  122.  
  123.  
  124.  
  125. $sql ="SELECT emote, image FROM emoticons";
  126. $result=mysql_query($sql);
  127.  
  128. print "<link rel=\"stylesheet\" type=\"text/css\" href=\"who-is-online/styles.css\" />";
  129.  
  130.  
  131. print "<center><div id='form'>";
  132. print "<div class=\"onlineWidget\"><img class=\"arrow\"><div class=\"panel\"><img class=\"preloader\" src=\"who-is-online/img/preloader.gif\" alt=\"Loading..\" width=\"22\" height=\"22\" /></div></div>";
  133. print "<br/><form method='post' id='form' name='form'>";
  134. print "<input type='text' id='message' name='message' rows='0' width='300px' size='55' style='margin-top:0px;margin-bottom:0px;margin-left:0px;'></textarea>";
  135. print "<input type='submit' class='submit' id='submit' name='submit' value='Send'></form>";
  136. print "<script language=\"Java Script\" type=\"text/javascript\">\n";
  137. print "function addSmiley(textToAdd)\n";
  138. print "{\n";
  139. print "document.form.message.value += textToAdd;";
  140. print "document.form.message.focus();\n";
  141. print "}\n";
  142. print "</script>\n";
  143.  
  144. print "</div></center>";
  145. ?>
  146.  
  147. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  148. <script type="text/javascript">
  149.         $(function(){
  150.                 $(".submit").click(function(){
  151.                         var message = $("#message").val();
  152.                         var dataString = 'message'+message;
  153.                         $.ajax({
  154.                                 type: "POST",
  155.                                 url: "submit.php?alt=json-in-script&callback=?",
  156.                                 var dataString = {'message' : message };
  157.                         });
  158.                         /*$message=$_POST['message'];
  159.         $name = $_SESSION['username'];
  160.     $room = $_SESSION['room'];
  161.     $user = $_SESSION['user'];*/
  162.                 });        
  163.         });
  164. </script>
clone this paste RAW Paste Data