phpでカレンダーでボタンが押されるたびに月の値を更新したいのにできません!
$_GET["btn"]の値がnullになってお帰りになります。
<?php if(isset($_GET["btn"])){ $ym = $_GET["btn"]; }else{ $ym = date("Y-m-1",strtotime("now")); } $prev = date("Y-m-1",strtotime("-1 month".$ym)); $next = date("Y-m-1",strtotime("+1 month".$ym)); var_dump($_GET["btn"]); var_dump($prev); var_dump($ym); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>カレンダーアプリ</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>my calender</h1> <?php // echo $this_month; ?> <form action="index.php" method="GET"> <input type="submit" name="btn" value="<?php $prev?>"> //null <input type="submit" name="btn" value="<?php $next?>"> //null <?php var_dump($ym); echo $ym; ?> </form> </div> </body> </html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/28 03:44
2022/05/28 04:57
2022/05/28 06:28