PHP/Jquery/MySQL Delete a row
Posted: Wed Feb 04, 2009 11:16 pm
So i have a page that displays groups with delete links that use Jquery to determine ID and then submit a PHP script through AJAX for the PHP delete function and then refresh the page. But all it does is refresh. I know its grabbing the variable containing the ID correctly through testing but I'm not sure whats wrong from there.
Thanks in advance for the help!
Originating page
delete_group.php
Edit: Removed parenthesis around $_POST['pid']
Thanks in advance for the help!
Originating page
Code: Select all
<?php include("includes/header_nav.php"); ?>
<div class="contwrapper">
<div class="textheader">Groups</div>
<div style="float:left; width:500px;">
<?php include("includes/db_connect.php"); ?>
<?php
//display all the news
$result = mysql_query("select * from groups");
echo "<ul>\n";
while($row = mysql_fetch_object($result))
{
echo "<li>$row->groupname <span><a href='#' class='delete-this'>Delete</a><input type='hidden' name='pid' value='$row->groupID'></span></li>\n";
}
echo "</ul>\n";
?>
<script type="text/javascript">
$(document).ready(function(){
$("a.delete-this").click(function(){
var groupid = $(this).next('input').val();
$.ajax({
type: "POST",
url: "includes/delete_group.php",
data: "pid=" + groupid,
success: window.location="groups.php"
});
});
});
</script>
Code: Select all
<?php
$con = mysql_connect("localhost","xxx","xxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mkeartco_castiron", $con);
$groupid = $_POST['pid'];
$sql = "DELETE FROM groups WHERE groupID='$groupid'";
$result = mysql_query($sql) or die("Unable to query:".mysql_error());
mysql_close($con);
?>