views:

20

answers:

2

Here is my question:

I have an approval page for user submitted entries to my site. The approval page has two radio buttons for each entry (approve or deny).

How can I make those radio buttons update the database table to 'approved' or 'denied'?

I have jQuery and would love to use that and the .post() function, just not sure on how that works.

Thanks in advance!

UPDATE: I understand that I was vague, that is not intended. I don't need the PHP processing, I just need to know how to submit the information to my PHP file using jQuery.

+2  A: 

This is a vague question but generally speaking, in your backend server, you need to setup a script that can inspect the content of a post request, extracts the ids of each record that has to update and then perform an update sql statement on the target table.

UPDATE

$.post("test.php", // server side script that will receive this request
       $("#testform").serialize() // serialized data 
);
Am
So, it's not possible to use jQuery just to submit it? I can do all the PHP file handling to actually process the data, I just don't understand the POST method with jQuery.
gamerzfuse
@gamerzfuze, I've updated my reply
Am
Thanks. I'm going to try and adapt this for my CodeIgniter setup and see how it goes.
gamerzfuse
+1  A: 

PHP will put the posted variable in the $_POST superglobal just as though a user had submitted them with regular old form submit functionality (assuming your HTTP headers are formatted correctly.) You can handle them by using the $_POST superglobal array keyed with the input element's name:

$isapproved = $_POST['approve'] //true false from your radio
$postid = $_POST['post_id'] //the id of the post being approved, probably a hidden form field.
$sql = 'UPDATE Posts SET Approved = ? WHERE PostID = ?';

//then execute using whatever database access model you prefer.
DeaconDesperado
Ah just read your edit - thought you meant the PHP handling. Check out this - http://jquery.malsup.com/form/#getting-started - an excellent jQuery plugin that uses the form's own action and method values to determine handling - well documented.
DeaconDesperado
No worries. Your answer was good for that though.
gamerzfuse
Do check out that plugin though - I think it may handle alot of the stuff you need for you. I've been using it with the guidance of the SO community all day today to build an event planning app and things are going really smoothly so far. Very cool options for nested callbacks that help the non-js initiated like myself.
DeaconDesperado
I checked it out. It seems to me there a few built-in functions in jQuery that make this plug-in unnecessary. Looking into it though!
gamerzfuse