Jump to content

delete ajax/php/mysql


adamlacombe

Recommended Posts

I have this code:

<script type="text/javascript">
$(document).ready(function() {
$('#load').hide();
});

$(function() {
$(".deletecom").click(function() {
$('#load').fadeIn();
var commentContainer = $(this).parent();
var id = $(this).attr("id");
var string = 'id='+ id ;

$.ajax({
   type: "POST",
   url: "files/joke_comment_remove.php",
   data: string,
   cache: false,
   success: function(){
commentContainer.slideUp('slow', function() {$(this).remove();});
$('#load').fadeOut();
  }
   
});

return false;
});
});
</script>

<a href='#' class='deletecom' id='$id'><img src='$domain/templates/$template/sources/images/bullet_delete.png ' />Remove Comment></a>

 

What it does right now is

$id=clean_up($_POST['id']);
mysql_query("DELETE FROM `comments` WHERE com_id='$id' AND com_name='{$_SESSION['id']}' OR com_id='$id' AND com_to='{$_SESSION['id']}'") or die(mysql_error());
?>

but what I want is:

$id=clean_up($_POST['id']);
$pageid=clean_up($_POST['pageid']);
mysql_query("DELETE FROM `feed` WHERE `pageid`='$pageid' AND `by`='{$_SESSION['id']}' AND `type`='jokecomment'") or die(mysql_error());
mysql_query("DELETE FROM `comments` WHERE com_id='$id' AND com_name='{$_SESSION['id']}' OR com_id='$id' AND com_to='{$_SESSION['id']}'") or die(mysql_error());
?>

 

so my question is, how do I add another $_POST into the ajax code I have; the id being "pageid"

 

Hope I was clear enough.

thanks in advanced!

Link to comment
https://forums.phpfreaks.com/topic/207669-delete-ajaxphpmysql/
Share on other sites

Firstly: This is a Javascript question. But here's how;

 

One: Add a new variable in the AJAX code next to id that houses the pageid by using the "name" attribute.

var id = $(this).attr("id");
var pageid = $(this).attr("name");
var string = 'id='+ id + '&pageid=' + pageid;

 

Two: Modify your a link to include the name attribute that will house your pageid.

<a href='#' class='deletecom' id='$id' name='$pageid'><img src='$domain/templates/$template/sources/images/bullet_delete.png ' />Remove Comment></a>

 

-cb-

Link to comment
https://forums.phpfreaks.com/topic/207669-delete-ajaxphpmysql/#findComment-1085630
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.