Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. INDEX.PHP
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5.     <head>
  6.         <title>Sample</title>
  7.         <link rel="stylesheet" type="text/css" href="style.css" />
  8.         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  9.     </head>
  10.     <body>
  11.         <textarea id="input"></textarea>
  12.         <br />
  13.         <input id="send" type="button" value="send" />
  14.         <script>
  15.             $("#send").click(function(){
  16.                 $("#input").val();
  17.                 $.ajax({
  18.                     type: 'POST',
  19.                     url: "test.php",
  20.                     data: "text="+$("#input").val(),
  21.                     success: function(data){ console.log(data); }
  22.                 });
  23.             });
  24.         </script>
  25.     </body>
  26. </html>
  27.  
  28. TEST.PHP
  29.  
  30. <?php
  31.     $text = $_POST["text"];
  32.    
  33.     $db = new PDO('pgsql:dbname=test;host=localhost;user=postgres;password=123');
  34.     $res = $db->query("insert into test values('$text')");
  35.    
  36.     echo "ok";
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement