-1

In fact im working on a small php script ! I have recently added some feature anyway i still have an issue which is : In html file i have put textarea and an submit input I want that when the user click on it the infos of textarea will be sent to a php file without refreshing the page ! Thank you.

1 Answers1

0

Then you should have a look at ajax:

http://api.jquery.com/jquery.ajax/

$("#mysubmitbutton").click(function() {
    $.ajax({
        url: "mywebsite.com/save-comment.php",
        type: "post",
        data: {commentText: $("#comment").val()},
        success: function(text) {
            if(text == "true") {
                alert("It worked! Your data were saved hurrayyy!");
            }
        },
        error: function() {
            alert("Print some error here!");
        }
   });        
});

On serverside accept your data:

$myText = $_POST["commentText"];
$query = "UPDATE comment SET text = '" . mysql_real_escape_string($myText) . "'";
if(mysql_query($query) == true) {
    echo "true";
} else {
    echo "false";
}
die();
Steini
  • 2,628
  • 13
  • 22
  • I don't want to use jquey ! – user3027295 Jan 06 '14 at 11:37
  • Well then google for an example script for "javascript ajax" and use that instead, the serverside stuff is basically the same but you gonna have a hard time if jquery is too hard for you, belive me... Besides, what is the point? JQuery is easy to use, slim and takes care of any browser compatiblity problems for you because it works as a general abstraction layer of JavaScript, But your choice then... – Steini Jan 06 '14 at 11:39
  • Jquery had a big size :( – user3027295 Jan 06 '14 at 11:54