PHPでエラー
PHPで一覧画面を作成していますが、
Warning: Undefined array key "status" in C:\xampp\htdocs\Portfolio\news_table.php on line 61
のエラーが出ます。
61行目
htmlspecialchars($_REQUEST['status'], ENT_QUOTES | ENT_HTML5, 'UTF-8'),]);
の「status」が未定義というエラーと思ってますが、
29行目で、
input type="checkbox" name="status" value="0" 未公開
と定義していて、エラー原因がわかりません。
因みに、「sdate」と「edate」ではエラーになってません。
原因をご教示いただけないでしょうか。
ソースコードを添付いたします。
<!doctype html>
<html lang=ja>
<head>
<meta charset="utf-8">
<title>News一覧</title>
<meta name="description" content="Salon Yuri-rinの管理者ページ">
<!--リセットcss-->
<link rel="stylesheet" href="https://unpkg.com/ress/dist/ress.min.css">
<!--css-->
<link rel="stylesheet" href="css/news_style.css">
<!--レスポンシブ対応-->
<meta name="viwport" content="width=device-width, initial-scale=1">
<!--Googleフォント-->
<link href="https://fonts.googleapis.com/css2?family=Sawarabi+Gothic&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@500&display=swap" rel="stylesheet">
</head>
<body>
<h1>News一覧</h1>
<form class="conditions" action="news_table.php" method="post">
<div class = "date">
<label>日付
<input type="date" name="sdate" id="sdate">
</label>
<label>~
<input type="date" name="edate" id="edate">
</label>
</div>
<label>ステータス
<input type="checkbox" name="status" value="0">未公開
<input type="checkbox" name="status" value="1">公開
</label>
<input type="submit" id="search" value="検索">
</form>
<table class="tablehead">
<tr>
<th class="header">日付</th>
<th class="header">タイトル</th>
<th class="header">内容</th>
<th class="header">公開ステータス</th>
<th class="header2">
<form class="create" action="news_create.php">
<input type="submit" name="button" value="登録" class="button_a">
</form>
</th>
<th class="header2"></th>
</tr>
</table>
<?php
try{
require_once("db_connect.php");
$pdo = new PDO("mysql:host=$SERV;dbname=$DB;charset=$CHAR",$USER,$PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$sql=$pdo->prepare
('select * from news where
(pub_date >= ? and pub_date <= ?)
and status = ?');
$sql->execute(
[htmlspecialchars($_REQUEST['sdate'], ENT_QUOTES | ENT_HTML5, 'UTF-8'),
htmlspecialchars($_REQUEST['edate'], ENT_QUOTES | ENT_HTML5, 'UTF-8'),
htmlspecialchars($_REQUEST['status'], ENT_QUOTES | ENT_HTML5, 'UTF-8'),]);
$stmt = $pdo->query($sql);
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($row as $data)
{
echo '<form action="?" method="post" class = "usertblform">';
//echo '<div class = "table1">';
echo '<table class="usertable">';
echo '<tr>';
echo '<input type="hidden" name="seq" value="' . htmlspecialchars($data['id'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '" id="seq">';
echo '<td class="dt">','<input type="text" name="sei" value="' . htmlspecialchars($data['pub_date'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '" id="sei" readonly="readonly">','</td>';
echo '<td class="dt">','<input type="text" name="mei" value="' . htmlspecialchars($data['title'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '" id=mei readonly="readonly">','</td>';
echo '<td class="dt">','<input type="text" name="sei_kana" value="' . htmlspecialchars($data['content'], ENT_QUOTES | ENT_HTML5, 'UTF-8') .'" id="sei_kana">','</td>';
echo '<td class="dt">','<input type="text" name="sei_kana" value="' . htmlspecialchars($data['status'], ENT_QUOTES | ENT_HTML5, 'UTF-8') .'" id="sei_kana">','</td>';
echo '<td class="bt">','<input type="submit" name=button value="修正" formaction="news_update.php" class="button_a">','</td>';
echo '<td class="bt">','<input type="submit" name=button value="削除" formaction="news_delete_conf.php" class="button_a">','</td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo "\n";
}
}
catch(PDOException $e){echo "次がエラーの内容です。;" .$e->getMessage();}
?>
</body>
</html>
0 likes