Page 1 of 1

Run mysql_query on a jquery request

Posted: Mon Nov 24, 2008 6:42 pm
by invisibled
I will try and explain this as best i can. I will post code below but just tell me to post any other info you need.

I have a CMS that i am building, and when a user goes to the "pages" section they can add edit or delete pages. So somebody clicks on the delete button and it shows a modal box (http://onehackoranother.com/projects/jquery/boxy/) and you can confirm yes or no that you want to delete that page. If you click no, the modal box goes away, and if you click yes, the modal box goes away and the page fades out from the listing.

So all that's missing is actually deleting the page from the database. But i cant figure out a way to run the mysql query to delete the page once the user has clicked the "yes" button. I would like to have no page refreshes in this process as well.

Suggestions?

Thanks,
-Shan

CODE:

//delete.php that gets called into the modal box

Code: Select all

<?php 
$id = $_GET['id'];
 
require '../../lib/inc/config.php';
 
print'<div>';
    print'<a href="" onclick="deleteRow();" class="close yes">Yes, Delete it.</a>';
    print'<a href="" class="close noo">Oops, Didn\'t mean to click that</a>';
print'</div>';
 
?>
 
<?php #mysql_query("DELETE FROM pages WHERE entryID = '$id'"); ?>
 
<script type="text/javascript">
    function deleteRow(){
        $("#row-<?php print $id; ?>").slideUp(500);
    }
</script>

Re: Run mysql_query on a jquery request

Posted: Mon Nov 24, 2008 10:12 pm
by requinix
Inside that deleteRow function you need to communicate with the web server, using AJAX or whatever jQuery offers you.
It will involve a URL you can send data to, something like

Code: Select all

delete.php?id=(id)&delete=yes
Instead of showing the delete confirmation, delete.php will do the actual deletion.

Re: Run mysql_query on a jquery request

Posted: Tue Nov 25, 2008 2:07 pm
by invisibled
I would like to not have to call another page though...