I’m having trouble getting two variables to post using ajax and jquery upon pressing a button on a confirm window. I can get either variable to display individually, but when I try to post two at the same time it won’t work.
EDIT – Problem solved. Didn’t include a file I needed. My fault!
echo '<input type="button" value="Delete" onclick="deleteSomething(\'' . $replyID .'\', \'' .$tableName. '\',\'' .$replyBy. '\')" />';
?>
<script type="text/javascript">
function deleteSomething(replyID, tableName, replyBy)
{
if (!confirm("Are you sure?"))
return false;
$.post('pageprocessing.php',"replyID=" + replyID + "&tableName=" + tableName + "&replyBy=" + replyBy, function(response) {
alert(response);
});
}
Here’s my script on pageprocessing.php. All three of the values that I post echo properly, I just can’t figure out why they aren’t being deleted.
if(isset($_POST['replyID']) && isset($_POST['tableName']) && isset($_POST['replyBy'])){
if($_POST['tableName'] == "replies" && $_POST['replyBy'] == $userid){
echo $replyID = $_POST['replyID']; //echoing variables to make sure the page gets this far
echo $replyBy = $_POST['replyBy'];
echo $tableName = $_POST['tableName'];
mysql_query("delete from replies where repliesID = $replyID "); //I can type this query into terminal and it deletes. Why won't it delete from here?
}
}
Your post’s variables should all be concatenated.
You could alternatively use objects