Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head><title>Ajax Test</title>
  4. <meta charset="utf-8" name="viewport" content="width=device-width initial-scale=1.0">
  5. <script>
  6. function exec(){
  7. var name=document.getElementById("name").value;
  8. var uname=document.getElementById("uname").value;
  9. var xtr=new XMLHttpRequest();
  10. xtr.onreadystatechange=function(){
  11. if(xtr.readyState==4 && xtr.status==4){
  12. document.getElementById("p_res").innerHTML=xtr.responseText;
  13. }
  14. };
  15. xtr.open("GET","insert.php?name="+name+"&uname="+uname,true);
  16. xtr.send(null);
  17. }
  18. </script>
  19. </head>
  20. <body>
  21. <form>
  22. Name : <input type="name" id="name"><br>
  23. Username : <input type="uname" id="uname"><br>
  24. <button type="button" onclick="exec()">Submit</button>
  25. </form>
  26. <div id="p_res"></div>
  27. </body>
  28. </html>
  29.  
  30. <?php
  31. class insert
  32. {
  33. /**
  34. * insert constructor.
  35. * @param $name
  36. * @param $uname
  37. */
  38. function __construct($name, $uname)
  39. {
  40. $conn = pg_connect("host=localhost dbname=test user=postgres password=password");
  41. if (!$conn) {
  42. return "Error, Could not connect!";
  43. }
  44. $query = "INSERT into test(uname,name) VALUES ('$uname','$name')";
  45. $res = pg_query($conn, $query) or die("Can not exec Query...");
  46. return (<<<ret
  47. Data Inserted Successfully...
  48. ret
  49. );
  50. }
  51. }
  52.  
  53. /** @var TYPE_NAME $obj_test */
  54. $obj_test=new insert($_GET['name'],$_GET['uname']);
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement