¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

½ñÀÒ/¼ÂÎã¤Ç¿È¤Ë¤Ä¤±¤ë¡ªMySQL¡ßPHP¤Ë¤è¤ëËܳÊWeb¡ÝDB¥·¥¹¥Æ¥àÆþÌç

Last-modified: 2018-11-14 (¿å) 15:24:17 (2214d)
Top / ½ñÀÒ / ¼ÂÎã¤Ç¿È¤Ë¤Ä¤±¤ë¡ªMySQL¡ßPHP¤Ë¤è¤ëËܳÊWeb¡ÝDB¥·¥¹¥Æ¥àÆþÌç

2006-09-20¡Á

½ñÀÒ¤ÎWeb¥Ú¡¼¥¸
http://www.gihyo.co.jp/books/syoseki.php/4-7741-1730-7

chap3

sample1

formÆþÎÏ¥Ú¡¼¥¸¢ª³Îǧ¥Ú¡¼¥¸¢ªÅÐÏ¿´°Î»¥Ú¡¼¥¸ ¤Î´ðËÜ
ÆþÎÏÃͤΥÁ¥§¥Ã¥¯¤Ï̵¤·

  1. index.html ... formÆþÎÏ¥Ú¡¼¥¸
  2. confirm.php ... ³Îǧ¥Ú¡¼¥¸
    1. hidden¤òÍѤ¤¤¿ÆþÎÏÃͤμõ¤±ÅϤ·ÊýË¡
  3. regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
    1. MySQL¥¢¥¯¥»¥¹ÊýË¡

sample2

  1. index.html ... formÆþÎÏ¥Ú¡¼¥¸
  2. confirm.php ... ³Îǧ¥Ú¡¼¥¸
    ¼¡¤Î£²¥Õ¥¡¥¤¥ë¤òrequire¤·¤Æ¤¤¤Þ¤¹¡£
    1. function.php ... gpc_stripslashes, gpc_addslashes, secho¤ÎÄêµÁ
    2. check_values.php ... ³ÆpostÃͤò¥Á¥§¥Ã¥¯¤·¡¢¥¨¥é¡¼¤ÎÏ¢ÁÛÇÛÎó($error['fname']Åù)¤òºîÀ®¤¹¤ë½èÍý
      Shift JIS¤ÇPHP¥³¡¼¥É¤ò½ñ¤¯¾ì¹ç¡¢ ¡Ömb_regex_encoding("Shift_JIS"); ¡×¤È½ñ¤¤¤Æ¤ª¤«¤Ê¤¤¤È¡¢¡Ömb_ereg("^[¥¡-¥ö¡¼]+$", $fname)¡×¤È¤¤¤Ã¤¿Ê¸¤Ç¡¢ ¡Ömbregex compile err: empty char-class¡×¤È¤¤¤Ã¤¿·Ù¹ð¤¬½Ð¤ë¾ì¹ç¤¬Í­¤ê¤Þ¤¹¡£ ¡Ê¡Ö¡¼¡×¤ÎShift JIS¥³¡¼¥É¤Ï¡¢0x815B¤Ç¡¢¡Ö5B¡×¤¬¡Ö[¡×¤Î¤¿¤á·Ù¹ð¤¬½Ð¤Þ¤¹¡Ë
  3. regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
    1. ºÆ¥Á¥§¥Ã¥¯¤Î¤¿¤á¡¢¾å¤Î£²¥Õ¥¡¥¤¥ë¤òrequire¤·¤Æ¤¤¤Þ¤¹¡£
    2. ¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤ò¥Æ¥ó¥×¥ì¡¼¥È¤È¤·¤¿¥á¡¼¥ëÁ÷¿®¥µ¥ó¥×¥ë¤Ç¤¹¡£
      1. mail.txt ... regist.php¤«¤é»ÈÍѤµ¤ì¤ë¡¢ÅÐÏ¿´°Î»¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¤Ç¤¹¡£
  4. downlist.php ... ¥À¥¦¥ó¥í¡¼¥É²èÌÌ
    1. MySQL¤ÇÁí·ï¿ô¤òÄ´¤Ù¤Æ¡¢É½¼¨¤·¤Æ¤¤¤Þ¤¹¡£
      $iCount = mysql_query("SELECT COUNT(*) AS NUM FROM ¥Æ¡¼¥Ö¥ë̾");
    2. <a href="download.php?...">1-100</a>¤È¤¤¤Ã¤¿¡¢¤É¤ÎÈϰϤò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤«¤òɽ¤¹¥ê¥ó¥¯¤Îµ­½ÒÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
    3. download.php ... tabʬ³ä¥Ç¡¼¥¿¤Î¥À¥¦¥ó¥í¡¼¥É¥×¥í¥°¥é¥à
      1. ¥Ö¥é¥¦¥¶¤Çtab¥Ç¡¼¥¿¤Î¥À¥¦¥ó¥í¡¼¥É¥À¥¤¥¢¥í¥°¤ò½Ð¤¹ÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
        $strFileName = ($_GET['iStartIndex'] + 1) . "-" . ($_GET['iStartIndex'] + $_GET['iDownloadCount']) . ".tab";
        header("Content-Type: text/tab-separated-values");
        header("Content-Disposition: attachment; filename=$strFileName");
        while($row = mysql_fetch_array($rs)) {
            $strRow = $row['iID'] . "\t" . $row['strName']. "\r\n";
            echo mb_convert_encoding($strRow, "SJIS");
        }
      2. MySQL¤Ç»ØÄêÈϰϤΥǡ¼¥¿¤ò¼èÆÀ¤¹¤ëÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
        $dbResult = mysql_query("SELECT * FROM ¥Æ¡¼¥Ö¥ë̾ LIMIT " . $_GET['iStartIndex'] . ", " . $_GET['iDownloadCount']);

sample3

  1. index.html ... formÆþÎÏ¥Ú¡¼¥¸
    sample2¤È¤Þ¤Ã¤¿¤¯Æ±¤¸¤Ç¤¹¡£
  2. index.php ... formÆþÎÏ¥Ú¡¼¥¸PHPÈÇ
    POSTÃͤò¼õ¤±¼è¤ê¡¢formÁ°²óÆþÎÏÃͤòÉüµ¢¤·¤Þ¤¹¡£
    index.html¤È¼¡¤Î£³ÅÀ¤¬°ã¤¤¤Þ¤¹¡£
    1. <?php
      session_start();
      require("function.php");
      require("check_values.php");
      $_SESSION['register'] = 0;
      ?>
    2. <form method="post" action="confirm.php?<?=SID?>">
    3. <input type="text" name="name" value="<?php secho($name) ?>" /><br />
  3. confirm.php ... ³Îǧ¥Ú¡¼¥¸
    ¼¡¤Î¤è¤¦¤Ë¥»¥Ã¥·¥ç¥ó¤òÍѤ¤¤¿¥»¥­¥å¥ê¥Æ¥£¥³¡¼¥É¤¬Äɲ䵤ì¤Æ¤¤¤Þ¤¹¡£
    1. session_start();
    2. $_SESSION['register']¤¬Ì¤ÄêµÁ¤Þ¤¿¤Ï£°°Ê³°¤Î¾ì¹ç¡¢error.html¤òɽ¼¨¤·¤Þ¤¹¡£
    3. ¡ÖÌá¤ë¡×¤ò²¡¤·¤¿¤È¤­¤Ë¡¢¡Öaction="index.php?<?=SID?>"¡×¤ò¸Æ¤Ó½Ð¤·¡¢ÆþÎÏÃͤòÊÝ»ý¤·¤¿ÆþÎϲèÌ̤òÉüµ¢¤µ¤»¤Æ¤¤¤Þ¤¹¡£
  4. regist.php ... ÅÐÏ¿´°Î»¥Ú¡¼¥¸
    ¼¡¤Î¤è¤¦¤Ë¥»¥Ã¥·¥ç¥ó¤òÍѤ¤¤¿¥»¥­¥å¥ê¥Æ¥£¥³¡¼¥É¤¬Äɲ䵤ì¤Æ¤¤¤Þ¤¹¡£
    1. session_start();
    2. $_SESSION['register']¤¬Ì¤ÄêµÁ¤Þ¤¿¤Ï£°°Ê³°¤Î¾ì¹ç¡¢error.html¤òɽ¼¨¤·¤Þ¤¹¡£
    3. MySQL¤Ç¥Æ¡¼¥Ö¥ë¤ò¥í¥Ã¥¯¤·¤Æ¤¤¤Þ¤¹¡£
      mysql_query("lock tables members write");
    4. Ʊ¤¸ÅŻҥ᡼¥ë¥¢¥É¥ì¥¹¤¬ÅÐÏ¿ºÑ¤ß¤Î¾ì¹ç¡¢·Ù¹ð¤òɽ¼¨¤·¤Æ¡¢ÅÐÏ¿¤òÈ´¤±¤Þ¤¹¡£
    5. MySQL¤ËÅÐÏ¿À®¸ù¸å¡¢¥»¥Ã¥·¥ç¥ó¤ÎÃͤò£²¤Ë¤·¤Æ¤¤¤Þ¤¹¡£

chap4

chap4.sql.txt

sample1

  1. regist.php ... ÆþÎÏ
  2. regist_confirm.php ... ³Îǧ
  3. regist_done.php ... ÅÐÏ¿´°Î»
  4. check_values.php ... ÆþÎÏ¥Á¥§¥Ã¥¯
  5. define.php ... ÄêµÁ¥Õ¥¡¥¤¥ë
  6. error.html ... ¥¨¥é¡¼É½¼¨
  7. list_simple.php
    1. MySQL¤Ç¿·¤·¤¤½ç¤Ë¼è¤ê½Ð¤¹SRL¤¬Ê¬¤«¤ê¤Þ¤¹¡£
    2. php¥×¥í¥°¥é¥à¤ÎÃæ¤Ç¡¢html¤ÎÃæ¤Ë¡Ö<?php ?>¡×¤ò¤Á¤ê¤Ð¤á¤Æ¡¢¥ë¡¼¥×¤ò¹½À®¤·¡¢¥Æ¡¼¥Ö¥ë¹Ô¤ò½ñ¤¯ÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
  8. list.php
    1. ¥»¥­¥å¥ê¥Æ¥£ÍѤ˥»¥Ã¥·¥ç¥óÊÑ¿ô¤ò½é´ü²½¤¹¤ë¥³¡¼¥É¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£
      session_start();
      $_SESSION['register'] = 0;
      $_SESSION['modify'] = 0;
      $_SESSION['delete'] = 0;
    2. ¥Ú¡¼¥¸¥¤¥ó¥Ç¥Ã¥¯¥¹¤òget¤Ç¼õ¤±¼è¤ê¡¢¡Ö¼¡¤Î??·ï¡×¡ÖÁ°¤Î??·ï¡×¤Î¥ê¥ó¥¯¤Ç¼«¿È¤ò¸Æ¤Ó½Ð¤·¡¢²èÌ̤ò¹¹¿·¤¹¤ëÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹¡£
    3. ¼¡¤Î³Æµ¡Ç½¤Îphp¥×¥í¥°¥é¥à¤ò¸Æ¤Ó½Ð¤¹¥ê¥ó¥¯¤¬Í­¤ê¤Þ¤¹¡£
      ¥ê¥ó¥¯¹àÌÜÈô¤ÓÀèphpµ¡Ç½
      ¿·µ¬ÅÐÏ¿index.php¥È¥Ã¥×¥Ú¡¼¥¸¤ËÌá¤ë
      ÊÔ½¸modify.phpÁª¤ó¤À¹Ô¤ÎÊÔ½¸
      ºï½üdelete_confirm.phpÁª¤ó¤À¹Ô¤Îºï½ü
  9. list_sort.php
  10. delete_confirm.php
  11. delete_done.php
  12. function.php
  13. modify.php
  14. modify_confirm.php
  15. modify_done.php

sample2

http://papuu.jp/develop/bk/0001/chap4/sample2/index.html

  1. check_values.php
  2. define.php
  3. delete_confirm.php
  4. delete_done.php
  5. error.html
  6. function.php
  7. list.php
  8. modify.php
  9. modify_confirm.php
  10. modify_done.php
  11. news.html
  12. news.php
  13. news2.php
  14. news_create.php
  15. news_template.html
  16. regist.php
  17. regist_confirm.php
  18. regist_done.php
  19. search.html

chap5

sample1

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (¡ó¿ôÃͤǷë²Ìɽ¼¨)

  1. index.php ... ¥é¥¸¥ª¥Ü¥¿¥ó¤ÇÁªÂò¤·¡¢result.php¤ò¸Æ¤Ó½Ð¤·¤Þ¤¹¡£
    1. ¥»¥Ã¥·¥ç¥ó¤Ë¤è¤ë£²½ÅÅêɼËɻߵ¡Ç½¤¬Í­¤ê¤Þ¤¹¡£
  2. result.php ... ÅÐÏ¿¡¦·ë²Ì²èÌÌɽ¼¨
    1. MySQL¤ÇÅêɼ¤òÅÐÏ¿¤·¤Þ¤¹¡£¡Ê¸«¤ë¤À¤±¤Î¾ì¹ç¤Ï¡¢ÅÐÏ¿¤·¤Þ¤»¤ó¡Ë
    2. MySQL¤ÇÅêɼ·ë²Ì¼èÆÀ¤·¤Þ¤¹¡£
    3. ¥»¥Ã¥·¥ç¥ó¤Ë¤è¤ë£²½ÅÅêɼËɻߵ¡Ç½¤¬Í­¤ê¤Þ¤¹¡£

sample2

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (dot.png¤òimg¥¿¥°¤Îwidth, height°À­¤Ç°ú¤­±ä¤Ð¤·¤Æ¡¢·ë²Ìɽ¼¨)

  1. index.php sample1¤È¤Þ¤Ã¤¿¤¯Æ±¤¸
  2. result.php
  3. dot.png

sample3

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (£·¿§¤Îpng²èÁü°ú¤­±ä¤Ð¤·¤Ç¡¢ÀѤ߾夲¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨

  1. index.php sample1¤È¤Þ¤Ã¤¿¤¯Æ±¤¸
  2. result.php
  3. 1.png¡Á7.png

sample4

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)

  1. index.php sample1¤È¤Þ¤Ã¤¿¤¯Æ±¤¸
  2. result.php
  3. 1.png¡Á7.png
  4. rs.png

sample5

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)

  1. index.php
    ¥³¥á¥ó¥ÈÆþÎÏÍóÄɲÃ
  2. result.php
  3. 1.png¡Á7.png
  4. rs.png
  5. error.html
  6. delete_confirm.php
  7. delete_done.php
  8. list.php

sample6

³¤³°Î¹¹ÔÀèÅêɼ¥·¥¹¥Æ¥à (±ß¥°¥é¥Õ¤Ç·ë²Ìɽ¼¨)

  1. index.php
    sample5¤È¤Þ¤Ã¤¿¤¯Æ±¤¸
  2. result.php
  3. 1.png¡Á7.png
  4. rs.png
  5. error.html
  6. delete_confirm.php
  7. delete_done.php
  8. list.php

chap6

sample1

sample2

sample3

sample4

chap7

sample1

ÊÙ¶¯¤·¤¿¤³¤È

  1. <input ... /><br />¤Î¤è¤¦¤Ë¡¢ÊĤ¸¤Ê¤¤¥¿¥°¤ÎºÇ¸å¤Ï¡¢É¬¤º¥¹¥é¥Ã¥·¥å¤òÆþ¤ì¤ë¡£
  2. PHP¤Ç¤Ïʸ»úÎó¤ÎÀÚ¤ìÌܤ¬Ê¬¤«¤ê¤Ë¤¯¤¤¤Î¤Ç¡¢Ê¸»úÎó¤òÏ¢·ë¤¹¤ë¥É¥Ã¥È¤ÎÁ°¸å¤Ï¡¢¥¹¥Ú¡¼¥¹¤òÆþ¤ì¤¿¤Û¤¦¤¬¸«¤ä¤¹¤½¤¦¡£
  3. SERVER_NAME¤ÈHTTP_HOST¤ÎÈæ³Ó
    $_SERVER["SERVER_NAME"];localhostÃͤò¼èÆÀ¤·¤Ê¤ó¤é¤«¤Î·Á¤ÇÍøÍѤ¹¤ë¾ì¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£¥ê¥¯¥¨¥¹¥È»þ¤Î host:〜 ¤ò»È¤¦¤â¤Î¤Î¡¢»ØÄ̵꤬¤¤¾ì¹ç¤Ï httpd.confÅù¤Ëµ­½Ò¤·¤¿ServerName¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤¬¥Ç¥Õ¥©¥ë¥È¤Ç»È¤ï¤ì¤Þ¤¹¡£htmlentities¤Ë¤è¤Ã¤Æ¥¨¥¹¥±¡¼¥×¤µ¤ì¤ë¤è¤¦¤Ç¤¹¡£
    $_SERVER["HTTP_HOST"];localhost:50000¥ê¥¯¥¨¥¹¥È¥Ø¥Ã¥À¡¼¤ÎÃͤò¤½¤Î¤Þ¤Þ¼è¤ê¤¿¤¤¾ì¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£¥ê¥¯¥¨¥¹¥È»þ¤Ë host:〜 ¤Ç»ØÄꤷ¤¿Ãͤ¬ÊÖ¤µ¤ì¤Þ¤¹¡£
  4. php.ini¤ÎÆüËܸ쥳¡¼¥ÉÀßÄê ÆüËܸì¤ÎÀßÄ꤬¹ç¤Ã¤Æ¤¤¤Ê¤¤¤È¡¢¡ÖParse error:¡×¤È¤¤¤Ã¤¿¥¨¥é¡¼¤¬½Ð¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£º£²ó¤¹¤Ù¤ÆShift JIS¤ËÅý°ì¤·¤Þ¤¹¤Î¤Ç¡¢¼¡¤Î¤è¤¦¤ËÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£ C:\Program Files\xampp\apache\bin\php.ini
    Directivedefaultchanged
    mbstring.detect_orderno value
    mbstring.encoding_translationOff
    mbstring.func_overload0
    mbstring.http_inputpass
    mbstring.http_outputpass
    mbstring.internal_encodingno value
    mbstring.languageneutral
    mbstring.strict_detectionOff
    mbstring.substitute_characterno value
    output_handler = mb_output_handler
    default_charset = "Shift_JIS"
    magic_quotes_gpc = Off
  5. id¤Î¹àÌܤò¡Öauto_increment¡×¤Ë¤·¤Ê¤¤¤È¡¢insert¤ÇMySQL¤ËÄɲ䷤Ƥ⡢ÄɲäǤ­¤Ê¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
    phpMyAdmin¤Ç¡Öauto_increment¡×¤ËÀßÄꤹ¤ëÊýË¡¤Ï¡¢¡Ö¤½¤Î¾¡×¤ÇÁªÂò¤·¤Þ¤¹¤Î¤Ç¡¢Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
  6. ¸å¤«¤éphpMyAdmin¤Çid¤òauto_increment¤ËÊѤ¨¤è¤¦¤È¤·¤Æ¡¢¼¡¤Î¥¨¥é¡¼¤È¤Ê¤ê¤Þ¤·¤¿¡£ ¡ÖDuplicate entry '1' for key 1 ¡× iId¤ò¤¤¤Ã¤¿¤óºï½ü¤·¤Æ¤«¤éÄɲä·¤¿¤é¡¢Âç¾æÉפǤ·¤¿¡£