Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";//to change that to our username
  4. $password = "";
  5. $dbname = "twitter";
  6.  
  7. $tweet = $_POST["tweet"]; // getting tweet from jquery script
  8.  
  9. $tweet = stripslashes($tweet);//stops there being any unwanted characters that the client didnt out in
  10. $tweet = mysql_real_escape_string($tweet);
  11.  
  12. $dataArray = array();
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. die("Connection failed: " . $conn->connect_error);
  18. }
  19.  
  20. $sql = "INSERT INTO twitter (tweet)
  21. VALUES ('$tweet')"; // inserting the text into the variable twitter/tweet
  22.  
  23. if ($conn->query($sql) === TRUE) {
  24. array_push($dataArray,"A new tweet has been posted");
  25. } else {
  26. array_push($dataArray,"No message has been posted");
  27. }
  28.  
  29. $conn->close();//closing the connection
  30.  
  31. echo json_encode($dataArray);//send the data back to browser for jquery to pick it up
  32. ?>
  33. <!--$ means variable-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement