Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Tommy

By: a guest on Feb 9th, 2010  |  syntax: None  |  size: 2.44 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. // K, background story: I installed a chat on my website, it's coded with a mixture of JavaScript, PHP, and MySQL.
  2. // MySQL tables are ajaxim_blocklists (blocked users), ajaxim_buddylists (this one should be obvious :P), ajaxim_chats (chatrooms), ajaxim_messages
  3. //(messages sent), and ajaxim_users (once again, obvious).
  4. //Fields for blocklists: id, user, buddy
  5. //Fields for buddylists: id, user, buddy, group
  6. //Fields for chats: room, user, id
  7. //Fields for messages: recipient, sender, message, type, stamp, id
  8. //Fields for users: username, password, email, is_online, last_ping, last_ip, banned, admin, buddyicon, profile, id
  9.  
  10. //So, I registered a user named "ChatBot", but didn't use the site to log in
  11. //Instead, I went into PHPMyAdmin, and set is_online to '1' (meaning online)
  12. //Next, I created a .php file "Bot.php"
  13.  
  14. <?php
  15. require('config.php');
  16. mysql_connect($sql_host, $sql_user, $sql_pass);
  17. mysql_select_db($sql_db);
  18.  
  19. $res = mysql_query("SELECT message FROM ".SQL_PREFIX."messages WHERE type = 'msg'");
  20.  
  21. while($arr = mysql_fetch_row($res)){
  22.    
  23. echo $arr[0]."<br />";
  24.     }
  25.  ?>
  26.  
  27. //So, that tells it to select the messages.
  28. //My first problem is that I need it to select more than just the message. I need it to select sender, recipient, and message.
  29. //Next problem is saving it to text.
  30. //I asked someone how to use PHP to save something to a .txt file.
  31. //He gave me this:
  32.  
  33. $myFile = "File.txt";
  34. $fh = fopen($myFile, 'w') or die("can't open file");
  35. $stringData = "$log\n";
  36. fwrite($fh, $stringData);
  37. $stringData = "meow\n";
  38. fwrite($fh, $stringData);
  39. fclose($fh);
  40.  
  41. //Next step, he said, was to save $res to a string, and write that string to the document, but he signed out before I had time to ask him how
  42. //to do that.
  43. //Another thing I want to do, is perhaps instead of .txt, make it .html, so I can format it, if at all possible. I want to have a table, sort of
  44. //like this:
  45.  __________________________________________________________________
  46. | Sender | Recipient | Message                                     |
  47.  ------------------------------------------------------------------
  48. |   *    |     *     |                      *                      |
  49.  ------------------------------------------------------------------
  50. //Where * corresponds to the text that goes in that field.
  51. //Except, hopefully an actual table, instead of just symbols.
  52. //Then, based off of this, I'll be able to create tables where type = 'event' or type = 'chatmsg'