Advertisement
mttprvst13

Chatroom Listener

Jul 30th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. include 'includes/main.inc.php';
  4.  
  5. if (isset($_POST['name']) && $_POST['name'] != '') {
  6.    
  7.     $today = date("Y-m-d");
  8.  
  9.     $select = $db->select("SELECT * FROM chat WHERE `date`=" . $db->mySQLSafe($today));
  10.     if ($select != null) {
  11.        
  12.         $chat = unserialize($select[0]['chat']);
  13.        
  14.         $chat[] = array('chat'=>$_POST['chat'], 'name'=>$_POST['name']);
  15.        
  16.         $db->update('chat', array('chat'=>$db->mySQLSafe(serialize($chat))), '`date`=' . $db->mySQLSafe($today));
  17.        
  18.     }else{
  19.        
  20.         $db->insert('chat', array('chat'=>$db->mySQLSafe(serialize(array(0=>array('chat'=>$_POST['chat'], 'name'=>$_POST['name'])))),
  21.                 'date'=>$db->mySQLSafe($today)));
  22.        
  23.     }
  24.    
  25. } else {
  26.  
  27.     $today = date("Y-m-d");
  28.  
  29.     $select = $db->select("SELECT * FROM chat WHERE `date`=" . $db->mySQLSafe($today));
  30.     if ($select != null) {
  31.         $chat = array_reverse(unserialize($select[0]['chat']));
  32.         foreach ($chat as $k => $l) {
  33.             echo $l['name'] . ': ' . $l['chat'] . '<br />';
  34.         }
  35.     } else {
  36.         echo 'There is no chat for today. How about you start some.';
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement