PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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);
?>
Edit: Removed parenthesis around $_POST['pid']
Last edited by grandroyal on Thu Feb 05, 2009 9:14 am, edited 1 time in total.
It's good that you are using AJAX with jQuery as I love both! However, if you are refreshing the whole page after the request, then you are kind of defeating the purpose of AJAX.
Anyway, are you are absolutely sure it is picking up the pid? Have you tried window.alert(groupid) before the AJAX call?
AJAX can be difficult to debug if it is the server side that is causing the issue. I tend to use Firebug for Firefox which allows me to view headers sent and the servers response, e.g. so I can see any errors that are being caused.
I think your main problem here is that you can't see what the remote script is doing, try running the remote script by itself, change the $_POST to a $_GET and pass a variable in manually.
Also, if you are simply posting, you may find it better and easier to use the jQuery post method, this is what I tend to use.
So I have it alert the groupid before the ajax call and that works fine, and i also used the delete_groups.php on its own and it works fine too.
The only thing I can think of is the ajax call messing things up but the page refreshes meaning it was successful right? I can try to use jquery's post instead but all of the documentation I found about it works only on form submit not click function. Can you show me what it would like like with my parameters?