Guest User

Untitled

a guest
Aug 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Load MySql table from bottom to top - PHP
  2. <html><head></head><body>
  3. <form action="chat.php" method="post">
  4. Message: <br><textarea type="text" name="message" style="width:80%; height:300px;"></textarea><br>
  5. <input type="submit" />
  6. </form>
  7.  
  8. <?php
  9.  
  10. $host="****";
  11. $user="****";
  12. $password="****";
  13.  
  14. $cxn = mysql_pconnect ($host, $user, $password);
  15.  
  16. mysql_select_db("defaultdb", $cxn);
  17.  
  18. if (getenv(HTTP_X_FORWARDED_FOR)) {
  19. $ipaddress = getenv(HTTP_X_FORWARDED_FOR);
  20. } else {
  21. $ipaddress = getenv(REMOTE_ADDR);
  22. }
  23.  
  24. $message = $_POST["message"];
  25.  
  26. mysql_query("INSERT INTO ChatTest (ID, TimeStamp, Message) VALUES ('$ipaddress', NOW(), '$message')");
  27.  
  28. $data = mysql_query("SELECT * FROM ChatTest") or die(mysql_error());
  29. Print "<table border cellpadding=3>";
  30. Print "<tr>";
  31. Print "<th>ID:</th><th>TimeStamp:</th><th>Message:</th>";
  32. while($info = mysql_fetch_array( $data )) {
  33. Print "<tr>";
  34. Print " <td>".$info['ID'] . "</td> ";
  35. Print " <td>".$info['TimeStamp'] . " </td>";
  36. Print " <td>".$info['Message'] . "</td></tr>";
  37. }
  38. Print "</table>";
  39.  
  40. mysql_close($cxn);
  41.  
  42.  
  43. ?>
  44. </body></html>
  45.  
  46. SELECT * FROM ChatTest
  47. ORDER BY `TimeStamp` DESC
  48.  
  49. 0'); DROP TABLE ChatTest --
  50.  
  51. INSERT INTO ChatTest (ID, TimeStamp, Message)
  52. VALUES ('$ipaddress', NOW(), '0'); DROP TABLE ChatTest --')
  53.  
  54. $message = mysql_real_escape_string($_POST['message']);
  55.  
  56. $data = mysql_query("SELECT * FROM ChatTest ORDER BY PostDate DESC") or die(mysql_error());
Add Comment
Please, Sign In to add comment