Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";//to change that to our username
- $password = "";
- $dbname = "twitter";
- $tweet = $_POST["tweet"]; // getting tweet from jquery script
- $tweet = stripslashes($tweet);//stops there being any unwanted characters that the client didnt out in
- $tweet = mysql_real_escape_string($tweet);
- $dataArray = array();
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO twitter (tweet)
- VALUES ('$tweet')"; // inserting the text into the variable twitter/tweet
- if ($conn->query($sql) === TRUE) {
- array_push($dataArray,"A new tweet has been posted");
- } else {
- array_push($dataArray,"No message has been posted");
- }
- $conn->close();//closing the connection
- echo json_encode($dataArray);//send the data back to browser for jquery to pick it up
- ?>
- <!--$ means variable-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement