hook表单提交,如何增加数据库字段?

发布于 2024-12-12 06:59:53 字数 493 浏览 0 评论 0原文

我在 drupal 中使用钩子形式更改。

如果字段留空,我希望它获取为该字段提交的最后一个值,并将其增加 0.01

我已经尝试过,

function uc_pa_form_submit($form, &$form_state) {
  global $user;
$maxbid = db_result(db_query('SELECT MAX(amount) FROM {uc_auction_bids} WHERE nid = %d', $node->nid));
  $input01 = (($maxbid) ? $maxbid : 0) + .01;

drupal_write_record('table', $input01);

但它没有更新任何内容,我知道 $input01 可以工作,因为我在不同的函数中尝试过它。

如果我更改 drupal_write_record('table', $input01);提交的值是有效的。

im using hook form alter in drupal.

If the fields left empty I want it to get the last value submitted for the field and increase it by .01

Ive tried

function uc_pa_form_submit($form, &$form_state) {
  global $user;
$maxbid = db_result(db_query('SELECT MAX(amount) FROM {uc_auction_bids} WHERE nid = %d', $node->nid));
  $input01 = (($maxbid) ? $maxbid : 0) + .01;

drupal_write_record('table', $input01);

but it isnt updating with anything, I know $input01 works as I tried it in a different function.

if i change drupal_write_record('table', $input01); to the value submitted it works.

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

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

发布评论

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

评论(2

思慕 2024-12-19 06:59:53

drupal_write_record() 期望第二个参数是一个对象,此时您正在传递一个数字。此外,如果您尝试更新记录,则需要提供表的主键作为第三个参数。像这样的事情:

$sql = 'SELECT * FROM FROM {uc_auction_bids} WHERE nid = %d ORDER BY amount DESC LIMIT 1';
$obj = db_fetch_object(db_query($sql));
$obj->amount = (($obj->amount) ? $obj->amount: 0) + .01;

drupal_write_record('uc_auction_bids', $obj, array('bid'));

drupal_write_record() expects the second argument to be an object, at the moment you're passing a number. Also, if you're trying to update a record you'll need to provide the table's primary keys as the third argument. Something like this:

$sql = 'SELECT * FROM FROM {uc_auction_bids} WHERE nid = %d ORDER BY amount DESC LIMIT 1';
$obj = db_fetch_object(db_query($sql));
$obj->amount = (($obj->amount) ? $obj->amount: 0) + .01;

drupal_write_record('uc_auction_bids', $obj, array('bid'));
飘然心甜 2024-12-19 06:59:53

我是新来的,希望我能发表评论而不是说我正在回答任何问题...

无论如何,$maxbid 是什么?它在比较之前的函数中不存在。是全球的吗?或者在代码示例中 $input 应该是 $maxbid (反之亦然)?

I'm new here and wish I could just comment rather than say I'm answering anything...

Anyway, what is $maxbid? It doesn't exist in the function before the comparison. Is it a global? Or should $input be $maxbid (or vice-versa) in your code sample?

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