i am using the following JQuery function to successfully POST data to the user_submit.php file, its just that the php file is unable to receive the data.

$(function() {
          $("#submit_js").click(function() {
            $.post("user_submit.php", {
              comment: $("#comment").val()
            });
          });
        });

upon finishing the Firebug consoloe shows this:

<html>
<body>

Your vote was successfully registered!any text but this
</body>
</html>

I am pasting the entire user_submit.php file here:

<html>
<body>

<?php

$vote = $_REQUEST['vote'];
$aid = $vote;


//$comment = $_REQUEST['#comment'];
//$comment = print_r($_POST);
$comment = htmlspecialchars($_POST["comment"]);
//$comment = $_POST['comment'];
//echo htmlspecialchars($comment);
//$comment = $_POST['comment'];
//echo $comment;

    // include configuration file
    include('config.php');

    // open database connection
    $connection = mysql_connect($host, $user, $pass) or die('ERROR: Unable to connect!');

    // select database
    mysql_select_db($db) or die('ERROR: Unable to select database!');

    // update vote counter
    $query = "UPDATE answers SET acount = acount + 1 WHERE aid = $vote";
    $result = mysql_query($query);
    $cadd = "INSERT INTO comments (comment,aid) VALUES ('$comment', '$aid')";
    mysql_query($cadd);

    // close connection
    mysql_close($connection);

    // print success message    
    echo 'Your vote was successfully registered!';
    echo $comment;
    //print_r(array_count_value($comment));

?>


</body>
</html>

please help me out. i have been stuck with this for hours now.

**HTML**

<div id="greetings">
                                You are voting out <b style="color: #00b0de;" id=roadiename></b>. Care to explain why?<br/><br/>
                                <textarea name="textarea" id="comment" cols="38" rows="7">textarea</textarea><br>
                                <a href="#" id="submit_js"><img src="images/submit.gif" style="border: none; float:right; padding-top: 10px;padding-right: 10px;"/></a>
                        </div>

Recommended Answers

All 3 Replies

Member Avatar for diafol
$vote = $_REQUEST['vote'];
$aid = $vote;

Perhaps I'm missing something, but from where does the $_REQUEST come? I assume it should be in the jQuery function, but I can't see it.

Therefore if it doesn't exist,

$query = "UPDATE answers SET acount = acount + 1 WHERE aid = $vote";

probably won't update .

//EDIT

Why the $aid variable?

You can use:

print_r ($_POST);

Just to be sure what it is receiving. If it is there as you believe then you can check line by line after that (echo'ing values where necessary) to see that it is what you expected.

It's because you miss the jQuery Callback function:

$(function() {
       $("#submit_js").click(function() {
            $.post("user_submit.php", {comment: $("#comment").val() }, function(fn) { alert (fn); } 
);
       });
    });

be sure that the POST data is being posted... see in firebug the post data.. check step by step... if you don't figure it out, try to remake the code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.