2012年2月13日月曜日

開発環境

  • OS X Lion - Apple(OS)
  • Apache (Web Server)
  • PHP (サーバーサイドプログラミング言語)
  • MySQL (データベース)
  • TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)

『初めてのPHP & MySQL 第2版』(Micbele E. Davis、Jon A. Phillips 著、西沢 直木 訳、オライリー・ジャパン、2008年、ISBN978-4-87311-365-4)の10章(フォームとの連携)の問題を解いてみる。

問10-1.

フォーム入力値を処理する際に、同じスクリプトを呼び出すのに使用できるスーパーグローバル変数は、$_SERVER['PHP_SELF']。

問10-2, 3.

sample50.php(コード(TextWrangler))

<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
    <title></title>
  </head>
  <body>
  <?php
    $username = htmlentities($_GET["username"]);
    $password = htmlentities($_GET["password"]);
    $self = htmlEntities($_SERVER['PHP_SELF']);
    if($username == '' || $password == ''){
      echo('
        <form action="'. $self . '" method="GET">
          <label>
            ユーザー名: <input type="text" name="username" />
          </label>
          <br />
          <label>
            パスワード: <input type="password" name="password" />
          </label>
          <input type="submit" value="submit" />
          <p>注意: 練習用で送信の際暗号化されないので、
          実際に使用しているパスワードは入力しないでください。</p>
        </form>');
    } else {
      echo "ユーザー名: <strong>$username</strong><br />";
      echo "パスワード: <strong>$password</strong<br />";
    }
  ?>
  </body>
</html>

問10-4.

「A」から始まる著者のみを抽出するクエリは、

select * from authors where author like 'A%';

併せて読んでいる書籍。

0 コメント:

コメントを投稿