Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2. if(isset($_GET['action'])){
  3.  
  4. if($_GET['action'] == "update"){
  5. $myServer = "(local)";
  6.  
  7. $myUser = "Gotactics";
  8.  
  9. $myPass = "gosteven22";
  10.  
  11. $myDB = "Gotactics";
  12. $link = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
  13.  
  14. $db = mssql_select_db($myDB, $link) or die("Couldn't open database $myDB");
  15. $res = mssql_query("SELECT * FROM User_Shoutbox ORDER BY date", $link);
  16. while(($row = mssql_fetch_array($res))&&($row['id']<=20)){
  17. $Date_Sent = date('d-m-Y', strtotime($row['date']));
  18. $result = $row['user'].$row['message'].$Date_Sent;
  19. echo $result;
  20. mssql_close($link);
  21. }
  22. if($_GET['action'] == "insert"){
  23. if(isset($_POST['message'])){
  24. $message = $_POST['message'];
  25. }
  26. if(isset($_POST['user'])){
  27. $message = $_POST['user'];
  28. }
  29. $myServer = "(local)";
  30.  
  31. $myUser = "Gotactics";
  32.  
  33. $myPass = "gosteven22";
  34.  
  35. $myDB = "Gotactics";
  36.  
  37. $link = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
  38.  
  39. $db = mssql_select_db($myDB, $link) or die("Couldn't open database $myDB");
  40. $query = "INSERT INTO User_Shoutbox(user, message) VALUES('".$user."','".$message."'";
  41. $res = mssql_query($query,$link);
  42. mssql_close($link);
  43. }}
  44.  
  45.  
  46.  
  47.  
  48. }
  49. else{
  50. header ("Location: index.php");
  51. }
  52.  
  53.  
  54.  
  55. /////////////////////////////////////////////////////
  56. This checks if the POST action is recieved into the methods. and if so it uses the Insert statement to Insert a table and Update to Show the table Now it shows the table fine but it does not Insert at all. instead of showing after insert or inserting it shows my web page inside a smaller version of the shoutbox.
  57. ////////////////////////////////////////////////////////
  58.  
  59.  
  60.  
  61. $("#form").submit(function(){
  62. if(checkForm()){
  63. var nick = inputUser.attr("value");
  64. var message = inputMessage.attr("value");
  65. //we deactivate submit button while sending
  66. $("#send").attr({ disabled:true, value:"Sending..." });
  67. $("#send").blur();
  68. //send the post to shoutbox.php
  69. $.ajax({
  70. type: "POST", url: "shoutbox.php", data: "action=insert&nick=" + nick + "&message=" + message,
  71. complete: function(data){
  72. messageList.html(data.responseText);
  73. updateShoutbox();
  74. //reactivate the send button
  75. $("#send").attr({ disabled:false, value:"Shout it!" });
  76. }
  77. });
  78. }
  79. else alert("Please fill all fields!");
  80. //we prevent the refresh of the page after submitting the form
  81. return false;
  82. });
  83.  
  84.  
  85. ///////////////////////////////////
  86. This posts the variable to the files in shoutbox.php to insert and update
  87. //////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement