Craig Hooghiem
Craig Hooghiem

Reputation: 1282

jQuery Post with Radio Button Value

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.

Upvotes: 0

Views: 539

Answers (2)

Mark Grey
Mark Grey

Reputation: 10257

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.

Upvotes: 1

Roman
Roman

Reputation: 10403

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 
);

Upvotes: 2

Related Questions