dongshi4078 2019-04-04 13:11
浏览 83
已采纳

too long

I've created a page where the user gets some information based on two dates (like 01/01/2019 and 04/04/2019). The user chooses both dates, which are sent to my sql query.

My issue is that I need to press the submit button twice for the dates to update.

From what I could see, the code is getting the dates from the previous submit and not the current one. For example, if I change one of the dates from 01/01/2019 to 01/02/2019, it will still be showing the info with 01/01/2019 as a date. I know that because I put some echos on the code and I can see that it's getting the previous value.

I've already tried the solutions from in php, why input form when submit it takes 2 times pressed, but nothing worked.

Here is the code where the user inputs the dates:

 <form action="code.php?titulo=Entrada_De_Soja_por_Variedade&codpag=soja&ini=<?php echo $ini ;?>&fin=<?php echo $fin ;?>" method="post">
    <input name="ini" id="ini"  type="date" value = "<?php echo $ini2 ?>" placeholder="<?php echo $ini ?>" >
    <input name="fin" id="fin" type="date"  value = "<?php echo $fin2 ?>" placeholder="<?php echo $fin ?>">
    <input style="width: 120px; height: 30px; font-size:14px;" type="submit" value="Search" />
</form>

$ini is the initial date and $fin is the final.

On the same code.php, I use:

$ini = $_POST['ini'];
$fin = $_POST['fin'];

On the sql query, I use:

$ini = $_GET['ini'];
$fin = $_GET['fin'];

What I need to know is if I'm using the right strategy to with $_POST and $_GET and if there is a way to fix this problem.

Thanks in advance and feel free to ask for more details if you need.

  • 写回答

1条回答 默认 最新

  • doubengshao8872 2019-04-04 13:55
    关注

    You can't pass variables via "POST" and recieve them via "GET".

    Also, you don't need to put the vars into the action URL, as they get appended automaticly when using method "GET".

    If you want the dates visibile inside the URL (to share the link) you could use this on the form-page:

     <form action="code.php" method="get">
    <input name="ini" id="ini"  type="date" value="<?php echo $_GET['ini']; ?>" placeholder="<?php echo $ini; ?>" >
    <input name="fin" id="fin" type="date"  value="<?php echo $_GET['fin']; ?>" placeholder="<?php echo $fin; ?>">
    <input style="width: 120px; height: 30px; font-size:14px;" type="submit" value="Search" />
    

    For more information on how "GET" and "POST" work, have a look at this:

    https://www.tutorialspoint.com/php/php_get_post.htm

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)