0

I'm using PHP, but I have some variables that I'd like to post to another page using JavaScript. However, I cannot get it to work. The strange thing is that I use this exact same function on some other pages, so I can't figure out why it's doing this.

The function is simply an input button (linked to a person's name and ID). When the button is pressed, I'd like for the name and ID to be posted to another page.

function flagPost(replyID, userName){
  if(!confirm("Flag Post?"))
    return false;
  $.post('postprocessing.php',"replyID=" + replyID + "&username=" +
    userName + "&tableName=testTable&category=flagPost",
    function(response){
      window.location.reload()
    }
  );
}

I know replyID and userName are being set correctly, because when I write the variables to the page, they display correctly.

function flagPost(replyID, userName){
  document.write(replyID + userName)

I even created a new page just to make sure something on postprocessing.php wasn't throwing off the POST.

I made this page titled postprocessing2.php where this was the only thing on it (aside from including the config file and whatnot).

$category = $_POST['category'];
  if($category == "flagPost"){
    $table = $_POST['tableName']; //just testing, I use escape strings in the "real" code
    $postID = $_POST['replyID'];
    $username = $_POST['username'];
    mysql_query("insert into flaggedPosts VALUES('','$postID','$table','$username')");
  }
4

1 回答 1

1

代替"replyID=" + replyID + "&username=" + userName + "&tableName=testTable&category=flagPost"

$.post(url,{ replyID: replyID, username: userName, tableName: "testTable", category: "flagPost"},function...
于 2013-06-02T09:19:58.417 回答