带有单选按钮值的 jQuery Post

发布于 2024-09-10 08:57:18 字数 248 浏览 2 评论 0原文

这是我的问题:

我有一个批准页面,供用户向我的网站提交条目。 批准页面对于每个条目都有两个单选按钮(批准或拒绝)。

如何使这些单选按钮将数据库表更新为“已批准”或“已拒绝”?

我有 jQuery,很想使用它和 .post() 函数,只是不确定它是如何工作的。

提前致谢!

更新:我知道我很含糊,这不是故意的。 我不需要 PHP 处理,我只需要知道如何使用 jQuery 将信息提交到我的 PHP 文件。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-09-17 08:57:18

这是一个模糊的问题,但一般来说,在后端服务器中,您需要设置一个脚本来检查 post 请求的内容,提取必须更新的每条记录的 id,然后在目标上执行更新 sql 语句桌子。

更新

$.post("test.php", // server side script that will receive this request
       $("#testform").serialize() // serialized data 
);

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 
);
扬花落满肩 2024-09-17 08:57:18

PHP 会将发布的变量放入 $_POST 超全局变量中,就像用户使用常规旧表单提交功能提交它们一样(假设您的 HTTP 标头格式正确。)您可以使用以输入为键的 $_POST 超全局数组来处理它们元素名称:

$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.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文