hook表单提交,如何增加数据库字段?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
drupal_write_record()
期望第二个参数是一个对象,此时您正在传递一个数字。此外,如果您尝试更新记录,则需要提供表的主键作为第三个参数。像这样的事情: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:我是新来的,希望我能发表评论而不是说我正在回答任何问题...
无论如何,$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?