duanpenpan5796 2016-03-16 17:44
浏览 23
已采纳

将数据放入点击日期的输入类型中

I have index.php and add.php. My question is when I click on a link of day in index.php, then go to add.php and store in input date the value of clicked day

index.php

<td><a href ="add.php"><?php $date1=date('y-m-d');echo $date1;?></a></td>

<td><a href ="add.php"><?php $date2=date('y-m-d' ,strtotime("+1day"));echo $date2;?></a></td>

add.php

<input type="date" name"date" >

I need that when click on date ,auto store in input without filling

  • 写回答

3条回答 默认 最新

  • dpwu16132 2016-03-16 18:14
    关注

    You can pass the the strtotime("+1 day") to the $_GET parameter, and extract it and pass it onto the value on your second page. Something like this for your index.php

    <td><a href="add.php?date=<?php echo time(); ?>"><?php echo date('y-m-d'); ?></a></td>
    <td><a href="add.php?date=<?php echo strtotime("+1 day"); ?>"><?php echo date('y-m-d', strtotime("+1 day")); ?></a></td>
    

    And in add.php you can fetch that value with $_GET['date'], which you can convert to a date with date("Y-m-d", $_GET['date']), which you add in as a value to the input.

    I've added the time into a ternary operator, so that you avoid getting Undefined index warnings. By default, it's set to be the date of today.

    <input type="date" name="date" value="<?php echo (!empty($_GET['date']) ? date("Y-m-d", $_GET['date']) : date("Y-m-d")); ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏