Guest User

Untitled

a guest
Feb 24th, 2017
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ■test29.php
  2. <?php
  3. var_dump($result);
  4. var_dump($pdo);
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xm1ns="http://www.w3.org/1999/xhtml">
  9. <html lang="ja">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  12. <meta http-equiv="Content-Script-Type" content="text/javascript">
  13.  
  14.  
  15. <title>単語集</title>
  16. </head>
  17. <body>
  18.     <style type="text/css">
  19. <!--
  20. BODY {
  21.     background-image: url(chocolate3-2.jpg);
  22.     background-repeat: no-repeat;
  23.     background-attachment: fixed;
  24.     background-position: right top;
  25. }
  26.  
  27. -->
  28. .font1 {
  29.     font-family: "あずきフォント";
  30. }
  31.  
  32. .font2 {
  33.     font-family: "あずきフォント";
  34.     font-size: 160%;
  35.     color: "#e4b9f9";
  36. }
  37.  
  38. .font3 {
  39.     /*  padding: 4px; */
  40.     /*  font-family: "あずきフォント"; */
  41. }
  42. .font4 {
  43.     position:relative;left:15px;
  44. }
  45. .font5 {
  46.     border-collapse: collapse; /* 枠線の表示方法 */
  47.     border: 1px #1C79C6 solid; /* テーブル全体の枠線(太さ・色・スタイル) */
  48. }
  49.  
  50. .font {
  51.     font-family: "あずきフォント";
  52.     font-size: 160%;
  53.     color: "white";
  54. }
  55.  
  56. .body {
  57.     cursor: url(hosi5.ani);
  58. }
  59.  
  60. @font-face {
  61.     font-family: 'あずきフォント'; /* お好きな名前に */
  62.     src: url('azuki.eot'); /* IE9以上用 */
  63.     src: url('azuki.eot?#iefix') format('embedded-opentype'), /* IE8以前用 */
  64.         url('azuki.woff') format('woff'), /* モダンブラウザ用 */
  65.         url('azuki.ttf') format('truetype'); /* iOS, Android用 */
  66. }
  67.  
  68. html,body {
  69.     scrollbar-base-color: #c3d7e0;
  70.     scrollbar-track-color: #c3d7e0;
  71.     scrollbar-face-color: #c3d7e0;
  72.     scrollbar-shadow-color: #c3d7e0;
  73.     scrollbar-darkshadow-color: #c3d7e0;
  74.     scrollbar-highlight-color: #c3d7e0;
  75.     scrollbar-3dlight-color: #c3d7e0;
  76.     scrollbar-arrow-color: #ffffff;
  77.     filter: chroma(color = #c3d7e0);
  78. }
  79. </style>
  80.         <table bgcolor="#882200" cellpadding="2" cellspacing="0">
  81. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  82. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  83. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  84. <td style="border:hotpink 1px solid;" rowspan="3" bgcolor="lightpink">
  85. <p>
  86. <p class="font1" ><font color="white">検索したい文字を入力して下さい</font></p>
  87. <form action="" method="post">
  88. <input type="hidden" name="command" value="search">
  89. <input type="text" name="keyword">
  90. <input type="submit" value="検索"style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;position:relative;left:20px;">
  91. </form>
  92. </p>
  93. <P align="right"><font size="2" color="hotpink">■■■</font></td>
  94. </tr>
  95. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  96. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  97. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td></tr>
  98. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  99. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  100. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td></tr>
  101. </table>
  102. <!--    ノートに書く -->
  103.     <table bgcolor="#882200" cellpadding="2" cellspacing="0">
  104. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  105. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  106. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  107. <td style="border:hotpink 1px solid;" rowspan="3" bgcolor="lightpink">
  108.         <p>
  109.         <img src="res-19.gif"><font color="white" class="font1">ノートに書く</font>
  110.         </p>
  111.         <p>
  112.         <form action="" method="post">
  113.         <font color="white" class="font1">ことば<input type="text" size="10" name="word">
  114.         意味<input type="text" size="30" name="sense"></br>
  115.         メモ<input type="text" class="font4" size="20" name="memo">
  116.         <input type="hidden" name="command" value="insert">
  117.         <input type="submit"  value="書く" style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;position:relative;left:20px;">
  118.         </form>
  119.         </p>
  120.  
  121.  
  122.  
  123. <P align="right"><font size="2" color="hotpink">■■■</font></td>
  124. </tr>
  125. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  126. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  127. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td></tr>
  128. <tr><td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  129. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td>
  130. <td style="border-top:chocolate 1px solid;border-left:chocolate 1px solid;border-bottom:black 1px solid;border-right:black 1px solid;" width="20" height="25" valign="bottom" align="right"><font color="peru" size="1"><b>」</b></font></td></tr>
  131. </table>
  132.     <form action="" method="post">
  133.     <button type="submit" name='button4' value='button4' style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;">修正</button>
  134.     </form>
  135.     <form action="" method="post">
  136.     <input type="hidden" name="command" value="listDisplay">
  137.     <input type="submit"  value="一覧表示" style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;">
  138.     </form>
  139. <!-- <table border="1" style="border-color:#6c2735; border-style:solid; border-width: 2px;" cellpading="0" border="1" width="80%"> -->
  140. <!--    <table class="font5"  cellpading="0" border="1" width="80%"> -->
  141.     <table width="80%"  rules="all" cellpading="0" border="1" style="border-color:brown;border-width:1px; border-style:solid;">
  142.         <caption class="font2">単語集</caption>
  143.         <tr style="background: #882200">
  144. <!--            <th width="30" height="35" class="font1"><font color="white">番号</font></th> -->
  145.             <th width="30" height="35" class="font1"><font color="white">ことば</font></th>
  146.             <th width="30" height="35" class="font1"><font color="white">意味</font></th>
  147.             <th width="30" height="35" class="font1"><font color="white">メモ</font></th>
  148.             <?php
  149.             if(isset($_POST['button4'])){
  150.                 echo '<th width="30" height="35" class="font1"><font color="white">更新</font></th>
  151.                     <th width="30" height="35" class="font1"><font color="white">削除</font></th>';
  152.                 }
  153.             ?>
  154.         </tr>
  155. <?php
  156. function h($str) {
  157.     return htmlspecialchars($str);
  158. }
  159. //PDO()コンストラクタ インスタンス初期化
  160. $pdo = new PDO('mysql:host=localhost;dbname=takahashi1;charset=utf8', 'takahashi', 'takahashi' );
  161. // もし修正ボタンが押されたら
  162. if ($_POST ['button4']) {
  163.     foreach ( $pdo->query ('select * from words order by id desc') as $row ) {
  164.         echo '<tr>';
  165.         echo '<form action="" method = "post">';
  166.         echo '<input type="hidden" name="command" value="update">';
  167.         echo '<input type="hidden" name="id" value="', $row ['id'], '">';
  168. //      echo '<td>', $row ['id'], '</td>';
  169.         echo '<td>';
  170.         echo '<input type="text" name="word" size="10" value="', $row ['word'], '">';
  171.         echo '</td>';
  172.         echo '<td>';
  173.         echo '<input type="text" name="sense" size="40" value="', $row ['sense'], '">';
  174.         echo '</td>';
  175.         echo '<td>';
  176.         echo '<input type="text" name="memo" size="20" value="', $row ['memo'], '">';
  177.         echo '</td>';
  178.         echo '<td><button type="submit" style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;">更新</button></td>';
  179.         echo '</form>';
  180.         echo '<form action="" method="post">';
  181.         echo '<input type="hidden" name="command" value="delete">';
  182.         echo '<input type="hidden" name="id" value="', $row ['id'], '">';
  183.         echo '<td><button type="submit" style="border: 1px solid #ff44ff; color: #ee00ff; background-color: #eeccff;">削除</button></td>';
  184.         echo '</form>';
  185.         echo '</tr>';
  186.         echo "\n";
  187.  
  188.     }
  189. }
  190. if(isset($_POST['command']) || !$_POST){
  191.     switch($_POST['command']){
  192.     case 'update':
  193.         //PDOのインスタンスを代入した変数$pdoを指定することでPDOクラスに用意された機能が利用可能になる
  194.         $result = $pdo->prepare('update words set word=?, sense=?, memo=? where id=?');
  195.         $result -> execute(array(h($_POST['word']),h($_POST['sense']),h($_POST['memo']),$_POST['id']));
  196.         break;
  197.     case 'delete':
  198.         $result = $pdo->prepare('delete from words where id=?');
  199.         $result->execute(array($_POST['id']));
  200.         break;
  201.     case 'insert':
  202.         //prepareメソッドはSQL文がセットされたPDOStatementインスタンスを返す
  203.         //このインスタンスはSQL文を実行するのに必要なので変数に代入
  204.         //prepareメソッドにSQL文を引数として渡す
  205.         //SQL文がセットされたPDOStatementインスタンスを変数$resultに代入する
  206.         $result = $pdo->prepare('insert into words values(null,?,?,?)');
  207.         $result->execute(array(h($_POST['word']),h($_POST['sense']),h($_POST['memo'])));
  208.         break;
  209.     case 'listDisplay':
  210.         break;
  211.     case 'search':
  212.         $vKeyword = isset($_POST['keyword'])?$_POST['keyword'] : '';
  213.         $result = $pdo->prepare('select * from words where word like ? or sense like ? or memo like ?');
  214.         $result->execute(array(
  215.                 '%' . $vKeyword . '%',
  216.                 '%' . $vKeyword . '%',
  217.                 '%' . $vKeyword . '%'
  218.         ) );
  219.         break;
  220.     }
  221.     if(!$_POST['command'] == 'search'){
  222.         $result = $pdo->query('select * from words order by id desc');
  223.     }
  224.     foreach ($result->fetchAll() as $row){
  225.         echo '<tr>';
  226.         //      echo '<td width="30"  height="35" align="center" width="110" height="35">', h($row['id']), '</td>';
  227.         echo '<td width="30" class="font3"><b>', h($row['word']), '</b></td>';
  228.         echo '<td width="150" class="font3">', h($row['sense']), '</td>';
  229.         echo '<td width="150" class="font3">', h($row['memo']), '</td>';
  230.         echo '</tr>';
  231.         echo "\n";
  232.         }
  233. }
  234. ?>
  235.  
  236. </table>
  237. </body>
  238. </html>
RAW Paste Data