Guest User

Untitled

a guest
Apr 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. function SubmitForm() {
  2. var input = $("#input").val();
  3. var user = "anon";
  4. $.post("post.php", {input: input, user: user}, function(data) {});
  5. alert("hello");
  6. }
  7.  
  8. function SubmitForm() {
  9. var input = $("#input").val();
  10. var user = "anon";
  11. $.post("post.php", {input: input, user: user}, function(data) {});
  12. }
  13.  
  14. <?php
  15.  
  16.  
  17. $dbhost = "xxx";
  18. $dbname = "xxx";
  19. $dbuser = "xxx";
  20. $dbpass = "xxx";
  21.  
  22. // Create connection
  23. $con = mysqli_connect($dbhost, $dbuser, $dbpass);
  24.  
  25. // Check connection
  26. if (!$con) {
  27. die("Database connection failed: " . mysqli_error());
  28. }
  29.  
  30. // Select database
  31. $db_select = mysqli_select_db($con, $dbname);
  32.  
  33. // Check selection
  34. if (!$db_select) {
  35. die("Database selection failed: " . mysqli_error());
  36. }
  37.  
  38. $message = $_POST["input"];
  39. $user = $_POST["user"];
  40. echo $message;
  41. echo $user;
  42.  
  43. $query = "INSERT INTO posts (user, message) VALUES ('$user', '$message')";
  44. mysqli_query($con, $query);
  45. ?>
  46.  
  47. <input type="submit" class="button" id="button_post" value="POST" onclick="SubmitForm(); return false;">
  48.  
  49. <input type="submit" class="button" id="button_post" value="POST">
  50.  
  51. <script>
  52. $(function(){
  53. $('#button_post').click(function(e){
  54. e.preventDefault();
  55. SubmitForm();
  56. });
  57. });
  58. </script>
  59.  
  60. function SubmitForm() {
  61. var input = $("#input").val();
  62. var user = "anon";
  63. $.post("post.php", {input: input, user: user}, function(data) {
  64. alert(data);
  65. });
  66. }
  67.  
  68. $.post("post.php", {input: input, user: user}, function(data) {
  69. // do anything that relies on this post here
  70. });
  71.  
  72. <input type="submit" class="button" id="button_post" value="POST" onclick="SubmitForm();">
  73.  
  74. <input type="button" ...
  75.  
  76. <input ... onclick="SubmitForm(); return false;">
  77.  
  78. $(window).load(function(){
  79. // your function here.
  80. });
Add Comment
Please, Sign In to add comment