doufu2496 2016-04-15 19:05
浏览 100
已采纳

如何通过按下提交按钮PHP来添加(或减去)一个值

I have the following code=>

<button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="<?php ?>">BACK</button>   
<button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="<?php ?>">FORWARD</button>

These buttons submit the form to the same page. At the top of the page I have variable $t which is initialized at value '0' and is followed by the codes=>

     $t=0;


if( $this->input->post('ileri') ) { $t=$t+1;} // Back  button was pressed; 
if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;

Now as I press forward I want to increase $t and when I press back I want to decrease it. But because of the declaration at the top ($t=0;) it goes as far as '1' with 'forward' and as back as '0' with 'back' buttons. Can anyone think of a way of getting over this problem. Thank you...

  • 写回答

3条回答 默认 最新

  • dsfbnhc4373 2016-04-15 19:16
    关注

    Add a hidden input, and store $t there. This gets posted upon submit:

    <?php
    $t = $this->input->post('t');
    if (!$t) $t = 0;
    if( $this->input->post('ileri') ) { $t=$t+1;} // Back  button was pressed; 
    if( $this->input->post('geri') ) { $t=$t-1;} // Forward button was pressed;
    ?>
    <input name="t" type="hidden" value="<?=$t ?>"> 
    <button class="btn btn-lg btn-warning text-center but-width" id="first" name="geri" type="submit" value="submit">BACK</button>   
    <button class="btn btn-lg btn-warning text-center but-width" id="second" name="ileri" type="submit" value="submit">FORWARD</button>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 谁会P4语言啊,我想请教一下
  • ¥20 win11无法启动 持续蓝屏且系统还原失败,无法开启系统保护
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛