Advertisement
Guest User

Untitled

a guest
May 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <html>
  2. <body>
  3. <title>[pts] Paste Text Service</title>
  4.  
  5. <?php
  6.  
  7. function dbConnect() {
  8. $host='localhost';
  9. $database='paste';
  10. $user='root';
  11. $pass='';
  12. mysql_connect($host, $user, $pass);
  13. mysql_select_db($database);
  14. }
  15.  
  16. function read ($id) {
  17. $result = mysql_query("SELECT * FROM paste_text WHERE id = '$id'");
  18. $tmp = mysql_fetch_assoc($result);
  19. return $tmp['text'];
  20. }
  21.  
  22. function write ($id, $text) {
  23. mysql_query("INSERT INTO paste_text (id, text) VALUES ('$id','$text')");
  24. } ?>
  25.  
  26. <? function inputForm($text) { ?>
  27. <form action="<?=$_SERVER['SCRIPT_NAME']?>" method="POST">
  28. <textarea name=textarea cols=45 rows=6><? echo $text; ?></textarea>
  29. <br><input type="submit" name="paste" value="Вставить">
  30. </form>
  31. <? }
  32.  
  33. function outputForm($text) { ?>
  34. <form action="<?=$_SERVER['SCRIPT_NAME']?>" method="POST">
  35. <textarea name=textarea cols=45 rows=6><? echo $text; ?></textarea>
  36. <br><input type="submit" name="paste" value="Вставить">
  37. </form>
  38. <? }
  39.  
  40. if (!isset($_REQUEST['paste'])) {
  41.  
  42. dbConnect();
  43. echo read($_GET['id'])."<br>";
  44. inputForm("");
  45.  
  46. } else {
  47.  
  48. dbConnect();
  49. $idUser = uniqid ('');
  50. write($idUser, $_REQUEST['textarea']);
  51. echo "готово";
  52. inputForm($_REQUEST['textarea']);
  53.  
  54. }
  55.  
  56. ?>
  57.  
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement