Run mysql_query on a jquery request

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!

Moderator: General Moderators

Post Reply
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

Run mysql_query on a jquery request

Post 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>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Run mysql_query on a jquery request

Post 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.
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

Re: Run mysql_query on a jquery request

Post by invisibled »

I would like to not have to call another page though...
Post Reply