Maya1991

WordSearch

Aug 3rd, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.98 KB | None | 0 0
  1. ▪️sample06-1.php
  2. <!-- http://localhost:8888/sample3/sample06-1.php -->
  3. <?php ini_set( 'display_errors', 1);?>
  4.  
  5.  
  6.  
  7.     <!--
  8. isset→引数に指定した変数が定義されているかどうか調べる変数
  9. &&は倫理演算子
  10. $a && $b $a又は$bが共にtrueの場合にtrue
  11. &&倫理積 2つの値が成り立つ時
  12. $_REQUEST→$_GET $_POST $_COOKIE $_FILESの値を取得します
  13.  
  14.  
  15. -->
  16.  
  17. <?php
  18. $japanese = "";
  19. $english = "";
  20. $example = "";
  21. // $id = "";
  22.  
  23. if (isset ( $_REQUEST ["japanese"] ) && isset ( $_REQUEST ["english"] ) && isset ( $_REQUEST ["example"] )) {
  24.     $japanese = $_REQUEST ["japanese"];
  25.     $english = $_REQUEST ["english"];
  26.     $example = $_REQUEST ["example"];
  27. //  $id = $_REQUEST ["id"];
  28. }
  29. ?>
  30.  
  31. <html>
  32. <head>
  33. <title>英単語メモ帳</title>
  34. <meta http-equiv="Content-Type" content="text/css" ; charset="UTF-8">
  35. <style type="text/css">
  36. div {
  37.     /*  padding: 100px; */
  38.     margin-left: 5px;
  39.     /*  margin-top: 1000px; */
  40.     background: url(yslr03.png);
  41.     background-repeat: no-repeat;
  42.     background-position: 100% 0%;
  43.     color: #000000;
  44.     scrollbar-base-color:white;
  45. }
  46.  
  47. iframe {
  48.     width: 1000px;
  49.     height: 500px;
  50.     /*  background: #ffffff url(top_mv_01_160203.png); */
  51.     background-attachment: fixed;
  52.     background: url(YSL-L5203900-main.png);
  53.     background-repeat: no-repeat;
  54.     background-position: 100% 100%;
  55. }
  56.  
  57. /* body{
  58.         scrollbar-arrow-color:deeppink;  */
  59. /*    scrollbar-face-color:mistyrose; */
  60. /*    scrollbar-highlight-color:white;  */
  61. /*    scrollbar-3dlight-color:white; */
  62. /*    scrollbar-track-color:white; */
  63. /*    scrollbar-shadow-color:hotpink; */
  64. /*    scrollbar-darkshadow-color:white;} */
  65.  
  66. </style>
  67.  
  68. </head>
  69. <body>
  70.     <img alt="http://www.emoticonswallpapers.com"
  71.         src="http://www.emoticonswallpapers.com/tipos/6/w.gif" />
  72.     <img alt="http://www.emoticonswallpapers.com"
  73.         src="http://www.emoticonswallpapers.com/tipos/6/o.gif" />
  74.     <img alt="http://www.emoticonswallpapers.com"
  75.         src="http://www.emoticonswallpapers.com/tipos/6/r.gif" />
  76.     <img alt="http://www.emoticonswallpapers.com"
  77.         src="http://www.emoticonswallpapers.com/tipos/6/d.gif" />
  78.     <img alt="http://www.emoticonswallpapers.com"
  79.         src="http://www.emoticonswallpapers.com/tipos/6/s.gif" />   
  80.     <img alt="http://www.emoticonswallpapers.com"
  81.         src="http://www.emoticonswallpapers.com/tipos/6/m.gif" />
  82.     <img alt="http://www.emoticonswallpapers.com"
  83.         src="http://www.emoticonswallpapers.com/tipos/6/e.gif" />
  84.     <img alt="http://www.emoticonswallpapers.com"
  85.         src="http://www.emoticonswallpapers.com/tipos/6/m.gif" />
  86.     <img alt="http://www.emoticonswallpapers.com"
  87.         src="http://www.emoticonswallpapers.com/tipos/6/o.gif" />
  88.     <br>
  89.     <a style="font-size: 11px;" href="http://www.emoticonswallpapers.com"></a>
  90.     <div>
  91.         <p>
  92.             <i frame src="sample06-2.php">英単語帳</iframe>
  93.        
  94.         </p>
  95.         <p>
  96.             <iframe src="sample06-2.php" allowtransparency="true">代替内容</iframe>
  97.         </p>
  98.  
  99.     </div>
  100. <body>
  101. <?php /* ?>
  102.     <form method="POST" action="input_do3.php">
  103.         <p>単語登録</p>
  104.         日本語 <input type="text" name="japanese" size="20" maxlength="255"
  105.             value="<?php echo $japanese;?>"> <br> 英語<input type="text"
  106.             name="english" size="20" maxlength="100"
  107.             value="<?php echo $english;?>"> <br> 例文<input type="text"
  108.             name="example" size="20" maxlength="100"
  109.             value="<?php echo $example;?>"> <input type="submit" value="登録">
  110.  
  111.     </form>
  112.  
  113.  
  114.     <!--表で表示-->
  115.  
  116.     <!--
  117. mysqli_connect_error直近の接続エラーの内容を文字列で返す
  118. or→又は
  119. mysqli_query→データベース上でクエリを実行する
  120. mysqli_set_charsetクライアントのデフォルト文字セットを設定する
  121. mysqli_fetch_assoc→結果の行を連想配列で取得する
  122. while文→ある条件が成り立っている間だけ処理を繰り返し実行する制御文
  123. 主に繰り返す回数がわからないときに使う
  124. <!--表を表示2(正)-->
  125. <?php
  126.  
  127. require ('dbconnect.php');
  128. $page = $_REQUEST ['page'];
  129. if ($page == '') {
  130.     $page = 1;
  131. }
  132. $page = max ( $page, 1 );
  133. $start = ($page - 1) * 5;
  134. $recordSet = mysqli_query ( $db, 'SELECT * FROM Cafe_data ORDER BY CafeEnglish DESC LIMIT ' . $start . ',5' );
  135. ?>
  136.  
  137. <table width="100%">
  138.         <tr align=center bgcolor=#ffe4b5>
  139.             <th scope="col">日本語</th>
  140.             <th scope="col">英語</th>
  141.             <th scope="col">例文</th>
  142.             <th scope="col">ID</th>
  143.             <th scope="col">編集</th>
  144.             <th scope="col">削除</th>
  145.         </tr>
  146.    
  147. <?php
  148. while ( $table = mysqli_fetch_assoc ( $recordSet ) ) {
  149.     ?>
  150.  
  151.     <tr>
  152.             <td rowspan=1 align=center bgcolor=#ffe4e1>
  153. <?php print(htmlspecialchars($table['CafeJapanese'])); ?></td>
  154.             <td><?php print(htmlspecialchars($table['CafeEnglish'])); ?></td>
  155.             <td><?php print(htmlspecialchars($table['CafeSignificance'])); ?></td>
  156.             <td><?php print(htmlspecialchars($table['ID'])); ?></td>
  157.  
  158.             <td><a
  159.                 href="uupdate_01.php?ID=<?php print(htmlspecialchars($table['ID']));?>">編集</a></td>
  160.             <td><a
  161.                 href="delete_01.php?ID=<?php print(htmlspecialchars($table['ID']));?>">削除</a></td>
  162.             </form>
  163.  
  164.         </tr>
  165.    
  166. <?php
  167. }
  168. ?>
  169. </table>
  170. <!--ulは順序のないリストを記述する-->
  171.     <ul class="paging">
  172.         <li><a href="sample06-1.php?page=<?php
  173.        
  174.         print ($page - 1) ;
  175.         ?>">前のページへ</a></li>
  176.         <li><a href="sample06-1.php?page=<?php
  177.        
  178.         print ($page + 1) ;
  179.         ?>">次のページへ</a></li>
  180.     </ul>
  181. <?php   */ ?>
  182.  
  183. </body>
  184. </html>
  185.  
  186.  
  187. ▪️sample06-2.php
  188. <!DOCTYPE html>
  189. <html>
  190. <head>
  191. <meta charset="UTF-8">
  192. <title>Insert title here</title>
  193. <style type="text/css">
  194. .example1 {
  195.     color: white;
  196. }
  197.  
  198. body {
  199.     scrollbar-track-color: #ffffff;
  200.     scrollbar-face-color: #ffffff;
  201.     scrollbar-arrow-color: #00efdb;
  202.     scrollbar-shadow-color: #00efdb;
  203.     scrollbar-highlight-color: #00efdb;
  204.     scrollbar-darkshadow-color: #ffffff;
  205.     scrollbar-3dlight-color: #ffffff;
  206. }
  207.  
  208. h1 {
  209.     font-size: 100%;
  210. }
  211.  
  212. p {
  213.     margin-top: 30px;
  214. }
  215. </style>
  216.  
  217. </head>
  218. <body>
  219. <?php
  220. $japanese = "";
  221. $english = "";
  222. $example = "";
  223.  
  224. if (isset ( $_REQUEST ["japanese"] ) && isset ( $_REQUEST ["english"] ) && isset ( $_REQUEST ["example"] )) {
  225.     $japanese = $_REQUEST ["japanese"];
  226.     $english = $_REQUEST ["english"];
  227.     $example = $_REQUEST ["example"];
  228. }
  229. ?>
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237. <html>
  238. <body>
  239.     <form method="POST" action="input_do3.php">
  240.         <p>単語登録</p>
  241.         日本語 <input type="text" name="japanese" size="30" maxlength="200"
  242.             value="<?php echo $japanese;?>"> <br> 英語<input type="text"
  243.             name="english" size="30" maxlength="100"
  244.             value="<?php echo $english;?>"> <br> 例文<input type="text"
  245.             name="example" size="30" maxlength="100"
  246.             value="<?php echo $example;?>"> <input type="submit" value="登録">
  247.  
  248.  
  249.  
  250. <br>
  251.  
  252.  
  253.  
  254.  
  255.     <!--表で表示-->
  256.  
  257.     <!--
  258. mysqli_connect_error直近の接続エラーの内容を文字列で返す
  259. or→又は
  260. mysqli_query→データベース上でクエリを実行する
  261. mysqli_set_charsetクライアントのデフォルト文字セットを設定する
  262. mysqli_fetch_assoc→結果の行を連想配列で取得する
  263. while文→ある条件が成り立っている間だけ処理を繰り返し実行する制御文
  264. 主に繰り返す回数がわからないときに使う
  265. <!--表を表示2(正)-->
  266. <?php
  267.  
  268. require ('dbconnect.php');
  269. $page = $_REQUEST ['page'];
  270. if ($page == '') {
  271.     $page = 1;
  272. }
  273. $page = max ( $page, 1 );
  274. $start = ($page - 1) * 5;
  275. /*
  276.  * DESK(Descending order)→大きい順に並べる。ASC(Ascending order)→小さい順に並べる
  277.  * LIMIT→件数を制限する
  278.  */
  279.  
  280. $recordSet = mysqli_query ( $db, 'SELECT * FROM Cafe_data ORDER BY ID DESC LIMIT ' . $start . ',5' );
  281. // $recordSet = mysqli_query( $db, 'SELECT * FROM Cafe_data ORDER BY ID DESK LIMIT ' . $start . ',5');
  282. // $recordSet = mysqli_query ( $db, 'SELECT * FROM Cafe_data ORDER BY CafeEnglish DESC LIMIT ' . $start . ',5' );
  283. ?>
  284.  
  285. <table width="100%">
  286.         <tr align=center bgcolor=hotpink>
  287.             <th scope="col"><font color="#FFFFFF">日本語</font></th>
  288.             <th scope="col" class="example1">英語</th>
  289.             <th scope="col" class="example1">例文</th>
  290.             <th scope="col" class="example1">ID</th>
  291.             <th scope="col" class="example1">編集</th>
  292.             <th scope="col" class="example1">削除</th>
  293.         </tr>
  294.    
  295. <?php
  296. while ( $table = mysqli_fetch_assoc ( $recordSet ) ) {
  297.     ?>
  298.  
  299.     <tr>
  300.             <td rowspan=1 align=center bgcolor=#ffe4e1>
  301. <?php print(htmlspecialchars($table['CafeJapanese'])); ?></td>
  302.             <td><?php print(htmlspecialchars($table['CafeEnglish'])); ?></td>
  303.             <td><?php print(htmlspecialchars($table['CafeSignificance'])); ?></td>
  304.             <td><?php print(htmlspecialchars($table['ID'])); ?></td>
  305.  
  306.             <td><a
  307.                 href="uupdate_01.php?ID=<?php print(htmlspecialchars($table['ID'], ENT_QUOTES));?>">編集</a></td>
  308.             <td><a
  309.                 href="delete_01.php?ID=<?php print(htmlspecialchars($table['ID'], ENT_QUOTES));?>">削除</a></td>
  310.             </form>
  311.  
  312.         </tr>
  313.    
  314. <?php
  315. }
  316. ?>
  317. </table>
  318.  
  319.     <ul class="paging">
  320.         <font color=pink><a
  321.             href="sample06-2.php?page=<?php
  322.            
  323.             print ($page - 1) ;
  324.             ?>">前のページへ</a></font>
  325.         <br>
  326.         <a href="sample06-2.php?page=<?php
  327.        
  328.         print ($page + 1) ;
  329.         ?>">次のページへ</a>
  330.     </ul>
  331.     <br>
  332.         <form action = "search.php" method="post">
  333. ワード検索:<input type="text" name="searchword" size="30" maxlength="100"
  334. value="<?php echo $searchword;?>">
  335. <input type="submit" value="検索">
  336. </form>
  337.     <h1>英単語集</h1>
  338.  
  339.     <table border=1 width=900>
  340.         <tr align=center bgcolor=#ffe4b5>
  341.             <td align=center>日本語</td>
  342.             <td align=center>英語</td>
  343.             <td align=center>例文</td>
  344.         </tr>
  345.         <tr>
  346.             <td rowspan=1 align=center bgcolor=#ffe4e1>なす</td>
  347.             <td>eggplant</td>
  348.             <td>Pickled cucumbers and egg plants.きゅうりとなすの揚げ物</td>
  349.         </tr>
  350.         <tr>
  351.             <td rowspan=1 align=center bgcolor=#ffe4e1>鰻</td>
  352.             <td>eel</td>
  353.             <td>a bowl of eel and rice鰻丼</td>
  354.         </tr>
  355.         <tr>
  356.             <td rowspan=1 align=center bgcolor=#ffe4e1>ぶり</td>
  357.             <td>yellowtail</td>
  358.             <td>I'm eating yellowtail.</td>
  359.         </tr>
  360.         <tr>
  361.             <td rowspan1 align=center bgcolor=#ffe4e1>カラス</td>
  362.             <td>crow</td>
  363.             <td>Stone the crows!</td>
  364.         </tr>
  365.         <tr>
  366.             <td rowspan1 align=center bgcolor=#ffe4e1>西洋かぼちゃ</td>
  367.             <td>squash</td>
  368.             <td>I ate a squash.</td>
  369.         </tr>
  370.         <tr>
  371.             <td rowspan1 align=center bgcolor=#ffe4e1>すずめ</td>
  372.             <td>sparrow</td>
  373.             <td>She is sparrow"s fart.</td>
  374.         </tr>
  375.         <tr>
  376.             <td rowspan1 align=center bgcolor=#ffe4e1>くらげ</td>
  377.             <td>jellyfish</td>
  378.             <td>I ate jellyfish last night.</td>
  379.         </tr>
  380.         <tr>
  381.             <td rowspan1 align=center bgcolor=#ffe4e1>ヒトデ</td>
  382.             <td>star fish</td>
  383.             <td>There are some starfishe in the sea.</td>
  384.         </tr>
  385.     </table>
  386.  
  387. </body>
  388. </html>
  389.  
  390. ▪️search.php
  391. <html>
  392. <body>
  393. // <?php
  394. // $db = mysqli_connect ( 'localhost', 'root', 'root', 'Cafe' ) or die ( mysqli_connect_error () );
  395. // mysqli_set_charset ( $db, 'utf8' );
  396. // ?>
  397. <?php
  398. //require→指定されたファイルを読み込み実行する(includeと同じ)
  399. require('dbconnect.php');
  400. $searchword=$_GET["searchword"];
  401. //フォームで送られてきた条件を元にSELECT文を作成
  402. // $sql = "SELECT * FROM Cafe_data WHERE CafeEnglish LIKE '%".$tango."%'";
  403. $sql = sprintf("SELECT * FROM Cafe_data WHERE CafeEnglish=searchword",
  404.         mysqli_real_escape_string($db, $_POST['searchword']));
  405.  
  406. //SELECT文を実行
  407. if (!$res = mysql_query($sql)) {
  408. echo "SQLエラー<br>" ;
  409. exit ;
  410. }
  411.  
  412. //検索結果表示
  413. echo "<table border=1>" ;
  414. echo "<tr><td>番号</td><td>用語</td><td>説明</td></tr>" ;
  415. while($row = mysql_fetch_array($res)){
  416. echo "<tr>" ;
  417. echo "<td>" . $row["ID"] . "</td>" ;
  418. echo "<td>" . $row["CafeEnglish"] . "</td>" ;
  419. echo "<td>" . $row["CafeJapanese"] . "</td>" ;
  420. echo "</tr>" ;
  421. }
  422. echo "</table>" ;
  423.  
  424. //結果セットの開放
  425. mysql_free_result ($res) ;
  426.  
  427. //データベースから切断
  428. mysql_close($con) ;
  429. ?>
  430. <p><a href="sample06-2.php">一覧に戻る</a></p>
  431.  
  432. </body>
  433. </html>
  434.  
  435. ▪️dbconnect.php
  436. <?php
  437. $db = mysqli_connect ( 'localhost', 'root', 'root', 'Cafe' ) or die ( mysqli_connect_error () );
  438. mysqli_set_charset ( $db, 'utf8' );
  439. ?>
  440.  
  441. ▪️delete_01.php
  442. <?php
  443. require ('dbconnect.php');
  444. $id = $_REQUEST['ID'];
  445. $sql = sprintf ( "DELETE FROM Cafe_data WHERE ID=%d",
  446.         mysqli_real_escape_string ( $db,$id )
  447. );
  448. mysqli_query ( $db, $sql ) or die ( mysqli_error ( $db ) );
  449. // mysqli_fetch_assoc — 結果の行を連想配列で取得する
  450. $recordSet = mysqli_fetch_assoc($recordSet);
  451. ?>
  452. <p>削除しました</p>
  453. <p><a href="sample06-2.php">一覧へ戻る</a></p>
  454.  
  455. ▪️uupdate.php
  456. <!-- ENT_QUOTES→ダブルクォート、シングルクォートの両方を変換します。 -->
  457. <?php ini_set('display_errors', 1 );?>
  458.  
  459. <?php
  460. require('dbconnect.php');
  461.  
  462. $id = $_REQUEST['ID'];
  463. $sql = sprintf("SELECT * FROM Cafe_data WHERE ID=%d",
  464.  mysqli_real_escape_string($db, $id)
  465.  );
  466.  $recordSet = mysqli_query($db, $sql);
  467.  $data = mysqli_fetch_assoc($recordSet);
  468.  ?>
  469.  
  470. <html>
  471. <body>
  472. <form id="frmUpdate" name="frmUpdate" method="post" action="input_do3_delete.php">
  473. <p>英単語集</p>
  474. <label for="japanese">日本語</label>
  475. <input name="japanese" type="text" id="japanese" size="20" maxlength="100"
  476. value="<?php print(htmlspecialchars($data['CafeJapanese'], ENT_QUOTES)); ?>" />
  477. <br>
  478. <label for ="english">英語</label>
  479. <input type="text" id="english" name="english" size="20" maxlength="100" value="<?php print(htmlspecialchars($data
  480. ['CafeEnglish'], ENT_QUOTES)); ?>" />
  481. <br>
  482. <label for = "example">例文</label><input type="text" id="example" name="example" size="20" maxlength="100" value="<?php print(htmlspecialchars($data
  483. ['CafeSignificance'], ENT_QUOTES)); ?>" />
  484.  
  485.  
  486. <input type="submit" value="変更する" />
  487. <input type="hidden" name="id" value="<?php print(htmlspecialchars($data['ID'], ENT_QUOTES)) ?>" />
  488. </form>
  489. </html>
  490.  
  491. ▪️input_do3.php
  492. <?php ini_set('display_errors', 1 );?>
  493. <html>
  494. <head>
  495.     <title>testtest</title>
  496. </head>
  497. <body>
  498.  
  499. <?php
  500. require('dbconnect.php');
  501.  
  502. //echo 'aaaa';
  503.  
  504. $sql = sprintf('INSERT INTO Cafe_data SET CafeJapanese="%s",
  505. CafeEnglish="%s", CafeSignificance="%s" ',
  506.    
  507.      mysqli_real_escape_string($db, $_POST['japanese']),
  508.      mysqli_real_escape_string($db, $_POST['english']),
  509.      mysqli_real_escape_string($db, $_POST['example'])
  510. );
  511. //echo $sql;
  512. mysqli_query($db, $sql) or die(mysqli_error($db));
  513.  
  514. ?>
  515.  
  516. <p>単語を登録しました</p>
  517. <p><a href="sample06-2.php">一覧に戻る</a></p>
  518.  
  519. ▪️input_do3_delete.php
  520. <?php ini_set('display_errors', 1 );?>
  521. <html>
  522. <head>
  523.     <title>testtest</title>
  524. </head>
  525. <body>
  526.  
  527. <?php
  528. require('dbconnect.php');
  529.  
  530. //echo 'aaaa';
  531.  
  532. $sql = sprintf('UPDATE Cafe_data SET CafeJapanese="%s",
  533. CafeEnglish="%s", CafeSignificance="%s" WHERE ID=%d',
  534.    
  535.      mysqli_real_escape_string($db, $_POST['japanese']),
  536.      mysqli_real_escape_string($db, $_POST['english']),
  537.      mysqli_real_escape_string($db, $_POST['example']),
  538.      mysqli_real_escape_string($db, $_POST['id'])
  539. );
  540. //echo $sql;
  541. mysqli_query($db, $sql) or die(mysqli_error($db));
  542.  
  543. ?>
  544.  
  545.  
  546. <p>単語を登録しました</p>
  547. <p><a href="sample06-2.php">一覧へ戻る</a></p>
Advertisement
Add Comment
Please, Sign In to add comment