php_value output_buffering OFF php_value default_charset UTF-8 php_value mbstring.detect_order SJIS,EUC-JP,JIS,UTF-8,ASCII php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.internal_encoding UTF-8 php_value mbstring.substitute_character none php_value mbstring.encoding_translation OFF |
<?php function sanitize($before) { foreach($before as $key=>$value) { $after[$key] = htmlspecialchars($value); } return $after; } ?> |
CREATE TABLE buch( no INT AUTO_INCREMENT, -- 蔵書No. title VARCHAR(100), -- タイトル isbn VARCHAR(100), -- ISBNコード author VARCHAR(100), -- 著者 publisher VARCHAR(100), -- 出版社 date VARCHAR(100), -- 発行年月日 PRIMARY KEY(no) -- 主キー ); |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書登録</title> <?php $title = ''; $isbn = ''; $author = ''; $publisher = ''; $date = ''; if(isset($_POST['title'])==true) { $title=htmlspecialchars($_POST['title']); } if(isset($_POST['isbn'])==true) { $isbn=htmlspecialchars($_POST['isbn']); } if(isset($_POST['author'])==true) { $author=htmlspecialchars($_POST['author']); } if(isset($_POST['publisher'])==true) { $publisher=htmlspecialchars($_POST['publisher']); } if(isset($_POST['date'])==true) { $date=htmlspecialchars($_POST['date']); } ?> </head> <body> <h1>蔵書登録</h1> <form method="post" action="buch_add_check.php"> <table border="5"> <tr> <td align="right">タイトル:</td> <td align="left"> <input type="text" name="title" style="width:200px" value="<?php ($title=='') ? : print $title; ?>"></td> </tr> <tr> <td align="right">ISBNコード:</td> <td align="left"> <input type="text" name="isbn" style="width:200px" value="<?php ($isbn=='') ? : print $isbn; ?>"></td> </tr> <tr> <td align="right">著者:</td> <td align="left"> <input type="text" name="author" style="width:200px" value="<?php ($author=='') ? : print $author; ?>"></td> </tr> <tr> <td align="right">出版社:</td> <td align="left"> <input type="text" name="publisher" style="width:200px" value="<?php ($publisher=='') ? : print $publisher; ?>"></td> </tr> <tr> <td align="right">発行年月日:</td> <td align="left"> <input type="text" name="date" style="width:200px" value="<?php ($date=='') ? : print $date; ?>"></td> </tr> <tr> <td align="center" colspan="2"> <input type="button" onclick="history.back()" value="戻る"> <input type="submit" value="OK"> </td> </tr> </table> </form> <br /> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書登録確認</title> </head> <body> <?php require_once('../common/common.php'); $post=sanitize($_POST); $title=$post['title']; $isbn=$post['isbn']; $author=$post['author']; $publisher=$post['publisher']; $date=$post['date']; if($title=='') { print 'タイトルが入力されていません。<br />'; } else { print 'タイトル:'.$title.'<br />'; } print 'ISBNコード:'.$isbn.'<br />'; print '著者:'.$author.'<br />'; print '出版社:'.$publisher.'<br />'; print '発行年月日:'.$date.'<br />'; if($title=='') { print '<form method="post" action="buch_add.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="isbn" value="'.$isbn.'">'; print '<input type="hidden" name="author" value="'.$author.'">'; print '<input type="hidden" name="publisher" value="'.$publisher.'">'; print '<input type="hidden" name="date" value="'.$date.'">'; print '<br />'; print '<input type="submit" value="戻る">'; print '</form>'; } else { print '上記の内容で登録します。'; print '<table border="0" frame="void" rules="none">'; print '<tr><td>'; print '<form method="post" action="buch_add.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="isbn" value="'.$isbn.'">'; print '<input type="hidden" name="author" value="'.$author.'">'; print '<input type="hidden" name="publisher" value="'.$publisher.'">'; print '<input type="hidden" name="date" value="'.$date.'">'; print '<br />'; print '<input type="submit" value="戻る">'; print '</form>'; print '</td><td>'; print '<form method="post" action="buch_add_done.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="isbn" value="'.$isbn.'">'; print '<input type="hidden" name="author" value="'.$author.'">'; print '<input type="hidden" name="publisher" value="'.$publisher.'">'; print '<input type="hidden" name="date" value="'.$date.'">'; print '<br />'; print '<input type="submit" value="OK">'; print '</form>'; print '</td></tr></table>'; } ?> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書登録完了</title> </head> <body> <?php try { require_once('../common/common.php'); $post=sanitize($_POST); $title=$post['title']; $isbn=$post['isbn']; $author=$post['author']; $publisher=$post['publisher']; $date=$post['date']; $dsn ='mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'INSERT INTO buch(title, isbn, author, publisher, date) VALUES (?,?,?,?,?)'; $stmt = $dbh->prepare($sql); $data[] = $title; $data[] = $isbn; $data[] = $author; $data[] = $publisher; $data[] = $date; $stmt->execute($data); $dbh = null; print 'タイトル:'.$title.'<br />'; print 'ISBNコード:'.$isbn.'<br />'; print '著者:'.$author.'<br />'; print '出版社:'.$publisher.'<br />'; print '発行年月日:'.$date.'<br />'; print '上記内容の書籍を蔵書に追加しました。<br />'; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書一覧</title> <?php $mode = 0; // ソート用のモードを切り替える為の変数 $searchword = ''; // あいまい検索用の変数 if(isset($_GET['mode'])==true) { $mode=$_GET['mode']; // GETメソッドで送信されたパラメータが存在する場合のみ、上書き } if(isset($_POST['searchword'])==true) { $searchword=htmlspecialchars($_POST['searchword']); // POSTメソッドで送信されたパラメータが存在する場合のみ、上書き } ?> </head> <body> <?php try { $dsn ='mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); if(isset($_POST['searchword'])==true) { $sql = 'SELECT no,title,author,publisher FROM buch WHERE title LIKE "%'.$searchword.'%"'; $stmt = $dbh->prepare($sql); $data[] = $searchword; $stmt->execute($data); } else { switch($mode){ case 0 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY no ASC'; break; case 1 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY no DESC'; break; case 2 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY title ASC'; break; case 3 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY title DESC'; break; case 4 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY author ASC'; break; case 5 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY author DESC'; break; case 6 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY publisher ASC'; break; case 7 : $sql = 'SELECT no,title,author,publisher FROM buch ORDER BY publisher DESC'; break; default : $sql = 'SELECT no,title,author,publisher FROM buch WHERE 1'; // case 0 とSQL文の内容は同義 break; } $stmt = $dbh->prepare($sql); $stmt->execute(); } $dbh = null; ?> <h1>蔵書一覧</h1> <form method="post" action="buch_list.php"> <input type="text" name="searchword" value="<?php print $searchword; ?>"> <input type="submit" value="検索"> </form> <br /> <table border="5"> <tr> <th colspan="7" align="right"> <form method="post" action="buch_add.php"> <input type="submit" name="add" value="蔵書登録"> </form> </th> </tr> <?php print '<tr>'; switch($mode){ case 0 : print '<th><a href="buch_list.php?mode=1">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 1 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 2 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=3">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 3 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 4 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=5">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 5 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; case 6 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=7">出版社</a></th>'; break; case 7 : print '<th><a href="buch_list.php?mode=0">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; default : print '<th><a href="buch_list.php?mode=1">No.</a></th>'; print '<th><a href="buch_list.php?mode=2">タイトル</a></th>'; print '<th><a href="buch_list.php?mode=4">著者</a></th>'; print '<th><a href="buch_list.php?mode=6">出版社</a></th>'; break; } print '<th>参照</th>'; print '<th>編集</th>'; print '<th>削除</th>'; print '</tr>'; while(true) { print '<tr>'; $rec = $stmt->fetch(PDO::FETCH_ASSOC); if($rec==false) { break; } print '<td align="right">'.$rec['no'].'</td>'; print '<td>'.$rec['title'].'</td>'; print '<td>'.$rec['author'].'</td>'; print '<td>'.$rec['publisher'].'</td>'; print '<td><a href="buch_disp.php?no='.$rec['no'].'">参照</a><//td>'; print '<td><a href="buch_edit.php?no='.$rec['no'].'">編集</a></td>'; print '<td><a href="buch_delete.php?no='.$rec['no'].'">削除</a></td>'; print '</tr>'; } } catch(Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> </table> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書情報参照</title> </head> <body> <?php try { $no=$_GET['no']; $dsn = 'mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT no,title,isbn,author,publisher,date FROM buch WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $rec = $stmt->fetch(PDO::FETCH_ASSOC); $title=$rec['title']; $isbn=$rec['isbn']; $author=$rec['author']; $publisher=$rec['publisher']; $date=$rec['date']; $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <h1>蔵書情報参照</h1> <table border="5"> <tr> <td>蔵書No.</td> <td><?php print $no; ?></td> </tr> <tr> <td>タイトル</td> <td><?php print $title; ?></td> </tr> <tr> <td>ISBNコード</td> <td><?php print $isbn; ?></td> </tr> <tr> <td>著者</td> <td><?php print $author; ?></td> </tr> <tr> <td>出版社</td> <td><?php print $publisher; ?></td> </tr> <tr> <td>発行年月日</td> <td><?php print $date; ?></td> </tr> </table> <br /> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書情報編集</title> </head> <body> <?php try { $no=$_GET['no']; $dsn = 'mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT no,title,isbn,author,publisher,date FROM buch WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $rec = $stmt->fetch(PDO::FETCH_ASSOC); $title=$rec['title']; $isbn=$rec['isbn']; $author=$rec['author']; $publisher=$rec['publisher']; $date=$rec['date']; $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <h1>蔵書情報編集</h1> <form method="post" action="buch_edit_check.php"> <table border="5"> <tr> <td>蔵書No.</td> <td><?php print $no; ?> <input type="hidden" name="no" value="<?php print $no; ?>"></td> </tr> <tr> <td>タイトル</td> <td><input type="text" name="title" style="width:200px" value="<?php print $title; ?>"></td> </tr> <tr> <td>ISBNコード</td> <td><input type="text" name="isbn" style="width:200px" value="<?php print $isbn; ?>"></td> </tr> <tr> <td>著者</td> <td><input type="text" name="author" style="width:200px" value="<?php print $author; ?>"></td> </tr> <tr> <td>出版社</td> <td><input type="text" name="publisher" style="width:200px" value="<?php print $publisher; ?>"></td> </tr> <tr> <td>発行年月日</td> <td><input type="text" name="date" style="width:200px" value="<?php print $date; ?>"></td> </tr> <tr> <td align="center" colspan="2"> <input type="button" onclick="history.back()" value="戻る"> <input type="submit" value="OK"> </td> </tr> </table> </form> <br /> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>編集内容確認</title> </head> <body> <?php require_once('../common/common.php'); $post=sanitize($_POST); $no=$post['no']; $title=$post['title']; $isbn=$post['isbn']; $author=$post['author']; $publisher=$post['publisher']; $date=$post['date']; if($title=='') { print 'タイトルが入力されていません。<br />'; } else { print 'タイトル:'.$title.'<br />'; } print 'ISBNコード:'.$isbn.'<br />'; print '著者:'.$author.'<br />'; print '出版社:'.$publisher.'<br />'; print '発行年月日:'.$date.'<br />'; if($title=='') { print '<form>'; print '<input type="button" onclick="history.back()" value="戻る">'; print '</form>'; } else { print '上記の内容で更新します。'; print '<form method="post" action="buch_edit_done.php">'; print '<input type="hidden" name="no" value="'.$no.'">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="isbn" value="'.$isbn.'">'; print '<input type="hidden" name="author" value="'.$author.'">'; print '<input type="hidden" name="publisher" value="'.$publisher.'">'; print '<input type="hidden" name="date" value="'.$date.'">'; print '<input type="button" onclick="history.back()" value="戻る">'; print '<input type="submit" value="OK">'; print '</form>'; } ?> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>編集完了</title> </head> <body> <?php try { require_once('../common/common.php'); $post=sanitize($_POST); $no=$post['no']; $title=$post['title']; $isbn=$post['isbn']; $author=$post['author']; $publisher=$post['publisher']; $date=$post['date']; $dsn ='mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'UPDATE buch SET title=?,isbn=?,author=?,publisher=?,date=? WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $title; $data[] = $isbn; $data[] = $author; $data[] = $publisher; $data[] = $date; $data[] = $no; $stmt->execute($data); $dbh = null; print '更新しました。<br />'; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>蔵書情報削除</title> </head> <body> <?php try { $no=$_GET['no']; $dsn = 'mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT title FROM buch WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $rec = $stmt->fetch(PDO::FETCH_ASSOC); $title=$rec['title']; $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <h1>蔵書情報削除</h1> <table border="5"> <tr> <td>蔵書No.</td> <td><?php print $no; ?></td> </tr> <tr> <td>タイトル</td> <td><?php print $title; ?></td> </tr> </table> <br /> この情報を削除してよろしいですか?<br /> <form method="post" action="buch_delete_done.php"> <input type="hidden" name="no" value="<?php print $no;?>"> <input type="button" onclick="history.back()" value="戻る"> <input type="submit" value="OK"> </form> <br /> <a href="buch_list.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>削除完了</title> </head> <body> <?php try { $no=$_POST['no']; $dsn ='mysql:dbname=buch;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'DELETE FROM buch WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> 削除しました。<br /> <br /> <a href="buch_list.php">戻る</a> </body> </html> |
CREATE TABLE bbs( no INT AUTO_INCREMENT, -- 記事No. title VARCHAR(100), -- タイトル username VARCHAR(100), -- 投稿者名 date TIMESTAMP, -- 投稿日時 comment TEXT(10000), -- 投稿記事内容 PRIMARY KEY(no) -- 主キー ); |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>掲示板</title> <?php $title = ''; $username = ''; $comment = ''; $mode = 0; // ソート用のモードを切り替える為の変数 if(isset($_GET['mode'])==true) { $mode=$_GET['mode']; // GETメソッドで渡されるパラメータがあった場合のみ上書き } if(isset($_POST['title'])==true) { $title=htmlspecialchars($_POST['title']); } if(isset($_POST['username'])==true) { $username=htmlspecialchars($_POST['username']); } if(isset($_POST['comment'])==true) { $comment=htmlspecialchars($_POST['comment']); } ?> </head> <body bgcolor="#efefef"> <?php try { $dsn ='mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT no,title,username,date,comment FROM bbs WHERE 1'; $stmt = $dbh->prepare($sql); $stmt->execute(); $dbh = null; ?> <h1>掲示板</h1> <form method="post" action="bbs_add_check.php"> <table border="0" frame="void" rules="none"> <tr> <td align="right">タイトル:</td> <td><input type="text" name="title" style="width:250px;background-color:#ffc0ff;" maxlength="100" value="<?php ($title=='') ? : print $title; ?>"></td> </tr> <tr> <td align="right">投稿者名:</td> <td><input type="text" name="username" style="width:250px;background-color:#c0ffc0;" maxlength="100" value="<?php ($username=='') ? : print $username; ?>"></td> </tr> <tr> <td align="right">投稿記事内容:</td> <td><textarea name="comment" rows="5" cols="50" style="background-color:#c0ffff;"> <?php ($comment=='') ? : print nl2br($comment); ?></textarea></td> </tr> <tr> <td> </td> <td><a href="bbs_list.php">[管理者用]</a> <input type="submit" name="add" value="投稿する"> </td></tr> </table> </form> <hr> <?php while(true) { print '<dl>'; $rec = $stmt->fetch(PDO::FETCH_ASSOC); if($rec==false) { break; } print '<dt>'.$rec['no'].' :<span style="color:#ff0000;">'.$rec['title'].'</span>'; print ' 投稿者名:<span style="color:#008000;">'.$rec['username'].'</span>'; print ' 投稿日時:<span style="color:#0000ff;">'.$rec['date'].'</span></dt>'; print '<dd>'.$rec['comment'].'</dd>'; print '</dl><hr>'; } } catch(Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>掲示板 [管理者用] </title> <?php $title = ''; $username = ''; $comment = ''; $mode = 0; // ソート用のモードを切り替える為の変数 if(isset($_GET['mode'])==true) { $mode=$_GET['mode']; // GETメソッドで渡されるパラメータがあった場合のみ上書き } if(isset($_POST['title'])==true) { $title=htmlspecialchars($_POST['title']); } if(isset($_POST['username'])==true) { $username=htmlspecialchars($_POST['username']); } if(isset($_POST['comment'])==true) { $comment=htmlspecialchars($_POST['comment']); } ?> </head> <body bgcolor="#efefef"> <?php try { $dsn ='mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); switch($mode){ case 0 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY no ASC'; break; case 1 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY no DESC'; break; case 2 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY title ASC'; break; case 3 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY title DESC'; break; case 4 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY username ASC'; break; case 5 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY username DESC'; break; case 6 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY date ASC'; break; case 7 : $sql = 'SELECT no,title,username,date,comment FROM bbs ORDER BY date DESC'; break; default : $sql = 'SELECT no,title,username,date,comment FROM bbs WHERE 1'; // case 0 とSQL文の内容は同義 break; } $stmt = $dbh->prepare($sql); $stmt->execute(); $dbh = null; ?> <h1>掲示板 [管理者用] </h1> <form method="post" action="bbs_add_check.php"> <table border="0" frame="void" rules="none"> <tr> <td align="right">タイトル:</td> <td><input type="text" name="title" style="width:250px;background-color:#ffc0ff;" maxlength="100" value="<?php ($title=='') ? : print $title; ?>"></td> </tr> <tr> <td align="right">投稿者名:</td> <td><input type="text" name="username" style="width:250px;background-color:#c0ffc0;" maxlength="100" value="<?php ($username=='') ? : print $username; ?>"></td> </tr> <tr> <td align="right">投稿記事内容:</td> <td><textarea name="comment" rows="5" cols="50" style="background-color:#c0ffff;"> <?php ($comment=='') ? : print nl2br($comment); ?></textarea></td> </tr> <tr> <td align="right" colspan="2"> <input type="submit" name="add" value="投稿する"> </td></tr> </table> </form> <br><hr><br> <table border="5"> <tr> <?php switch($mode){ case 0 : print '<th><a href="bbs_list.php?mode=1">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 1 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 2 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=3">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 3 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 4 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=5">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 5 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; case 6 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=7">投稿日時</a></th>'; break; case 7 : print '<th><a href="bbs_list.php?mode=0">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; default : print '<th><a href="bbs_list.php?mode=1">No.</a></th>'; print '<th><a href="bbs_list.php?mode=2">タイトル</a></th>'; print '<th><a href="bbs_list.php?mode=4">投稿者名</a></th>'; print '<th><a href="bbs_list.php?mode=6">投稿日時</a></th>'; break; } ?> <th>投稿記事内容</th> <th>編集</th> <th>削除</th> </tr> <?php while(true) { print '<tr>'; $rec = $stmt->fetch(PDO::FETCH_ASSOC); if($rec==false) { break; } print '<td align="right">'.$rec['no'].'</td>'; print '<td>'.$rec['title'].'</td>'; print '<td>'.$rec['username'].'</td>'; print '<td>'.$rec['date'].'</td>'; print '<td>'.$rec['comment'].'</td>'; print '<td><a href="bbs_edit.php?no='.$rec['no'].'">編集</a></td>'; print '<td><a href="bbs_delete.php?no='.$rec['no'].'">削除</a></td>'; print '</tr>'; } } catch(Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> </table> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>投稿内容確認</title> </head> <body> <?php require_once('../common/common.php'); $post=sanitize($_POST); $title=$post['title']; $username=$post['username']; $comment=$post['comment']; if($title=='') { print 'タイトルが入力されていません。<br />'; } else { print 'タイトル:'.$title.'<br />'; } if($username=='') { print '投稿者名が入力されていません。<br />'; } else { print '投稿者名:'.$username.'<br />'; } if($comment=='') { print '投稿記事内容が入力されていません。<br />'; } else { print '投稿記事内容:<br />'.nl2br($comment).'<br />'; // \nを<br>に変換して表示 } if($title=='' || $username=='' || $comment=='') { print '<form method="post" action="bbs.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="username" value="'.$username.'">'; print '<input type="hidden" name="comment" value="'.$comment.'">'; print '<input type="submit" value="戻る">'; print '</form>'; } else { print '上記の記事内容で投稿します。'; print '<table border="0" frame="void" rules="none">'; print '<tr><td>'; print '<form method="post" action="bbs.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="username" value="'.$username.'">'; print '<input type="hidden" name="comment" value="'.$comment.'">'; print '<input type="submit" value="戻る">'; print '</form>'; print '</td><td>'; print '<form method="post" action="bbs_add_done.php">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="username" value="'.$username.'">'; print '<input type="hidden" name="comment" value="'.$comment.'">'; print '<input type="submit" value="OK">'; print '</form>'; print '</td></tr></table>'; } ?> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>投稿完了</title> </head> <body> <?php try { require_once('../common/common.php'); $post=sanitize($_POST); $title=$post['title']; $username=$post['username']; $comment=nl2br($post['comment']); // \nを<br>に変換 $dsn ='mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'INSERT INTO bbs(title, username, comment) VALUES (?,?,?)'; $stmt = $dbh->prepare($sql); $data[] = $title; $data[] = $username; $data[] = $comment; $stmt->execute($data); $dbh = null; print 'タイトル:'.$title.'<br />'; print '投稿者名:'.$username.'<br />'; print '投稿記事内容:<br />'.$comment.'<br />'; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <a href="bbs.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>記事内容編集</title> </head> <body> <?php try { $no=$_GET['no']; $dsn = 'mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT no,title,username,date,comment FROM bbs WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $rec = $stmt->fetch(PDO::FETCH_ASSOC); $title=$rec['title']; $username=$rec['username']; $date=$rec['date']; $comment=$rec['comment']; $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <?php $comment = str_replace("<br>","",$comment); // <br>タグを削除 $comment = str_replace("<br />","",$comment); // <br />タグを削除 ?> <h1>記事内容編集</h1> <form method="post" action="bbs_edit_check.php"> <table border="5"> <tr> <td>記事No.</td> <td><?php print $no; ?> <input type="hidden" name="no" value="<?php print $no; ?>"></td> </tr> <tr> <td>タイトル:</td> <td><input type="text" name="title" style="width:250px;background-color:#ffc0ff;" maxlength="100" value="<?php print $title; ?>"></td> </tr> <tr> <td>投稿者名:</td> <td><input type="text" name="username" style="width:250px;background-color:#c0ffc0;" maxlength="100" value="<?php print $username; ?>"></td> </tr> <tr> <td>投稿日時:</td> <td><?php print $date; ?> <input type="hidden" name="date" value="<?php print $date; ?>"></td> </tr> <tr> <td>投稿記事内容:</td> <td><textarea name="comment" rows="5" cols="50" style="background-color:#c0ffff;"> <?php print $comment; ?></textarea></td> </tr> <tr> <td align="center" colspan="2"> <input type="button" onclick="history.back()" value="戻る"> <input type="submit" value="OK"> </td> </tr> </table> </form> <br /> <a href="bbs.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>編集内容確認</title> </head> <body> <?php require_once('../common/common.php'); $post=sanitize($_POST); $no=$post['no']; $title=$post['title']; $username=$post['username']; $date=$post['date']; $comment=$post['comment']; if($title=='') { print 'タイトルが入力されていません。<br />'; } else { print 'タイトル:'.$title.'<br />'; } if($username=='') { print '投稿者名が入力されていません。<br />'; } else { print '投稿者名:'.$username.'<br />'; } if($comment=='') { print '投稿記事内容が入力されていません。<br />'; } else { print '投稿記事内容:<br />'.nl2br($comment).'<br />'; // \nを<br>に変換して表示 } if($title=='' || $username=='' || $comment=='') { print '<form>'; print '<input type="button" onclick="history.back()" value="戻る">'; print '</form>'; } else { print '上記の内容で更新します。'; print '<form method="post" action="bbs_edit_done.php">'; print '<input type="hidden" name="no" value="'.$no.'">'; print '<input type="hidden" name="title" value="'.$title.'">'; print '<input type="hidden" name="username" value="'.$username.'">'; print '<input type="hidden" name="date" value="'.$date.'">'; print '<input type="hidden" name="comment" value="'.$comment.'">'; print '<input type="button" onclick="history.back()" value="戻る">'; print '<input type="submit" value="OK">'; print '</form>'; } ?> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>編集完了</title> </head> <body> <?php try { require_once('../common/common.php'); $post=sanitize($_POST); $no=$post['no']; $title=$post['title']; $username=$post['username']; $date=$post['date']; $comment=nl2br($post['comment']); // \nを<br>に変換 $dsn ='mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'UPDATE bbs SET username=?,title=?,date=?,comment=? WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $username; $data[] = $title; $data[] = $date; $data[] = $comment; $data[] = $no; $stmt->execute($data); $dbh = null; print '更新しました。<br />'; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <a href="bbs.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>投稿記事削除</title> </head> <body> <?php try { $no=$_GET['no']; $dsn = 'mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'SELECT username,date,comment FROM bbs WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $rec = $stmt->fetch(PDO::FETCH_ASSOC); $username=$rec['username']; $date=$rec['date']; $comment=$rec['comment']; $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> <h1>投稿記事削除</h1> <table border="5"> <tr> <td>記事No.</td> <td><?php print $no; ?></td> </tr> <tr> <td>投稿者名</td> <td><?php print $username; ?></td> </tr> <tr> <td>投稿日時</td> <td><?php print $date; ?></td> </tr> <tr> <td>投稿記事内容</td> <td><?php print $comment; ?></td> </tr> </table> <br /> この記事を削除してよろしいですか?<br /> <form method="post" action="bbs_delete_done.php"> <input type="hidden" name="no" value="<?php print $no;?>"> <input type="button" onclick="history.back()" value="戻る"> <input type="submit" value="OK"> </form> <br /> <a href="bbs.php">戻る</a> </body> </html> |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>削除完了</title> </head> <body> <?php try { $no=$_POST['no']; $dsn ='mysql:dbname=bbs;host=localhost'; $user = 'root'; $password = ''; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf8'); $sql = 'DELETE FROM bbs WHERE no=?'; $stmt = $dbh->prepare($sql); $data[] = $no; $stmt->execute($data); $dbh = null; } catch (Exception $e) { print 'ただいま障害により大変ご迷惑をお掛けしております。'; exit(); } ?> 削除しました。<br /> <br /> <a href="bbs.php">戻る</a> </body> </html> |