Q&A
実現したいこと
Forbidden
You don't have permission to access this resourceを解決して編集や削除完了ページに移動したいです。
前提
ここに質問の内容を詳しく書いてください。
phpでtodoリストを作成しています。
編集ページ→確認ページ→編集完了ページと移動していきたいのですが、なぜか編集確認ページ→編集完了ページ、削除確認ページから削除完了ページに移動しようとするとForbidden
You don't have permission to access this resource. Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.2.0 Server at localhost Port 80というような表示が出てしまい、urlはhttp://localhost/todoapp/newtask_delete_done.php%3E%3Cinput%20type=というようなものに変わってしまいます。なぜか編集ページ、削除ページからそれぞれ編集完了、削除完了ページには確認ページを挟まない場合は移動できます。
特に設定をいじったりはしていません。また、これまでに同じような確認ページから完了ページへといったようなサイトを作成しましたが、forbiddenされてしまうことはありませんでした。
解決方法や解決するために読むべきサイトなどがありましたら教えて頂けると嬉しいです。
発生している問題・エラーメッセージ
エラーメッセージはなし 編集ページ→確認ページ→編集完了ページと移動していきたいのですが、なぜか編集確認ページ→編集完了ページ、削除確認ページから削除完了ページに移動しようとするとForbidden You don't have permission to access this resource. Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.2.0 Server at localhost Port 80というような表示が出てしまい、urlはhttp://localhost/todoapp/newtask_delete_done.php%3E%3Cinput%20type=というようなものに変わってしまう。
該当のソースコード
php
1newtask_delete.php 2<!doctype html> 3<html lang="ja"> 4<head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" 7 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 8 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 9 <title>Delete Page</title> 10</head> 11<body> 12<?php 13try { 14 require_once('putTogether.php'); 15 //$newtask_title = filter_input(INPUT_POST, 'title'); 16 $NewTaskNum = filter_input(INPUT_GET, 'ID'); 17 18 require_once('db_connect.php'); 19 db_connect(); 20 $dbh = db_connect(); 21 22 $sql = 'SELECT title, content FROM posts WHERE ID= :ID'; 23 $stmt = $dbh->prepare($sql); 24 $stmt->bindParam(":ID", $NewTaskNum, PDO::PARAM_STR); 25 $stmt->execute(); 26 27 $rec = $stmt->fetch(PDO::FETCH_ASSOC); 28 $NewTaskTitle = $rec['title']; 29 $NewTaskContents = $rec['content']; 30} catch (Exception $e) { 31 $e->getMessage(); 32 exit(); 33} 34 35 36?> 37<h1> 38 ToDo Delete Page 39</h1> 40<form action="newtask_delete_check.php" method="post"> 41<input type="hidden" name="newtask_code" value="<?php echo $NewTaskNum;?>"> 42<div style="margin: 10px"> 43 <label for="title">タイトル:</label> 44 <input type="text" name="title" value="<?php echo $NewTaskTitle;?>"> 45 </div> 46 <div style="margin: 10px"> 47 <label for="content">内容:</label> 48 <input type="text" name="content" value="<?php echo $NewTaskContents;?>"> 49 50 </div> 51 <button type="submit" name="post">削除する</button> 52 <button type="button" onclick="history.back()">戻る</button> 53</form> 54 55</body> 56</html>
php
1newtask_delete_check.php 2<!doctype html> 3<html lang="ja"> 4<head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" 7 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 8 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 9 <title>check Page</title> 10</head> 11<body> 12<?php 13require_once('putTogether.php'); 14require_once('check.php'); 15 16try { 17 TitleCheck($NewTaskTitle); 18 ContentCheck($NewTaskContents); 19 LengthCheck($NewTaskTitle); 20 //titleとcontentがあってタイトル<20 21 if ($NewTaskTitle != '' && $NewTaskContents != '' && mb_strlen($NewTaskTitle) < $limit) { 22 echo '<form method="post" action="newtask_delete_done.php>'; 23 echo '<input type="hidden" name="newtask_code" value="'.$NewTaskNum.'">'; 24 echo '<input type="hidden" name="title" value="'.$NewTaskTitle.'">'; 25 echo '<input type="hidden" name="contents" value="'.$NewTaskContents.'">'; 26 echo '<input type="button" onclick="history.back()" value="戻る">'; 27 echo '<input type="submit" value="OK">'; 28 echo '</form>'; 29 } else { 30 echo '<form>'; 31 echo '<input type="button" onclick="history.back()" value="戻る">'; 32 echo '</form>'; 33 } 34} catch (Exception $e) { 35 exit($e->getMessage()); 36} 37?> 38</body> 39</html>
php
1newtask_delete_done.php 2<!DOCTYPE html> 3<html lang="en"> 4<head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>Delete done page</title> 9</head> 10<body> 11<?php 12try { 13 require_once('putTOgether.php'); 14 require_once('db_connect.php'); 15 $NewTaskNum = filter_input(INPUT_POST, 'newtask_code'); 16 17 db_connect(); 18 $dbh = db_connect(); 19 20 $sql = 'DELETE FROM posts WHERE ID= :ID'; 21 $stmt = $dbh->prepare($sql); 22 $stmt->bindParam(":ID", $newtasknum, PDO::PARAM_STR); 23 $stmt->execute(); 24} catch (Exception $e) { 25 exit($e->getMessage()); 26} 27?> 28<?php echo $NewTaskTitle; ?> 29<p>を削除しました</p> 30<br> 31<a href="list.php">戻る</a> 32</body> 33</html>
試したこと
teratailで同じような質問があるか調べる。
書籍と削除、編集確認ページのコードを確認する。
削除ページと確認ページのページの移動の仕方を確認して違いがないかを考える。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/02/22 09:15
2023/02/22 09:25
2023/02/28 01:50