0

hello i want to get text from textarea and register in database but not work where is problem thanks all. $get_text show empty value.

<script type="text/javascript">
    $(function() {
        $(".new_post").click(function(){
            var get_text = $("#post_text").val();
            $.ajax({
                type: "POST",
                url: "ajax/ajax_new_post.php",
                data: get_text,
                success: function() {
                    alert(get_text);
                    $('#post_text').val('');
                    //$(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
                    //.animate({ opacity: "hide" }, "slow");
                }
            });
            return false;
        });
    });
</script>
<body>
   <textarea id="post_text" placeholder="What's on your mind?"></textarea>
</body>

ajax_new_post.php

$get_text = $_GET['get_text'];
mysqli_query($Connection, "INSERT INTO posts VALUES('$ID', '$get_text')");

4 Answers 4

1

You are missing key. Change your data to:

data: { get_text : $("#post_text").val() },

And your type is POST, so use $_POST['get_text'] in PHP file.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using post method . So use $_POST['get_text'];

2 Comments

Are you sure about $_POST['get_text'] ?
I think so > lets have atry
0

The problem is that you are making a POST and trying to get the value as GET.

Use :

$get_text = $_POST['get_text'];
mysqli_query($Connection, "INSERT INTO posts VALUES('$ID', '$get_text')");

1 Comment

Are you sure about $_POST['get_text'] ?
0

Use jQuery to send a JavaScript variable to your PHP file:

'$url = 'path/to/phpFile.php';
 $.get($url, {name: get_name(), job: get_job()});'

In your PHP code, get your variables from $_GET['name'] and $_GET['job'] like this:

<?php
    $buffer_data['name'] = $_GET['name'];
    $buffer_data['job']  = $_GET['job'];
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.