jQuery and MySQL

Posted by Wayne on Stack Overflow See other posts from Stack Overflow or by Wayne
Published on 2010-05-21T20:19:13Z Indexed on 2010/05/21 20:30 UTC
Read the original article Hit count: 195

Filed under:
|
|
|
|

I have taken a jQuery script which would remove divs on a click, but I want to implement deleting records of a MySQL database. In the delete.php:

<?php 

$photo_id = $_POST['id'];

$sql = "DELETE FROM photos
  WHERE id = '" . $photo_id . "'";

$result = mysql_query($sql) or die(mysql_error());

?>

The jQuery script:

$(document).ready(function() {
   $('#load').hide();
});

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

$.ajax({
   type: "POST",
   url: "delete.php",
   data: string,
   cache: false,
   success: function(){
 commentContainer.slideUp('slow', function() {$("#photo-" + id).remove();});
 $('#load').fadeOut();
  }

 });

return false;
 });
});

The div goes away when I click on it, but then after I refresh the page, it appears again...

How do I get it to delete it from the database?

Thanks :)

EDIT: Woopsie... forgot to add the db.php to it, so it works now >.<

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about mysql