ブログシステムの構築1(データベース)

htdogsにblogフォルダーを作る。








phpMyAdminのデータベースを以下のようにつくる。
















「entry_id」:「A_I」にチェックする。


テーブルができたこを確認






dreamweaverとの接続










新規PHPファイル作成「index.php」を作成し、MySQL接続の設定(テーブルができていることが大前提)ちなみにXHTML 1.0 Transitionalで作成(HTML5だと何か問題がおこるかもしれないので)











先ほどphpMyAdimnのテーブルがDWで連動されていることがわかる。







「admin」フォルダーを作成
新規PHP作成。ファイル名を「input.php」とする




<?php require_once('../Connections/MyBlogdatabase.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formMain")) {
  $insertSQL = sprintf("INSERT INTO entry_table (subject, digest, `document`) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['subject'], "text"),
                       GetSQLValueString($_POST['digest'], "text"),
                       GetSQLValueString($_POST['document_text'], "text"));

  mysql_select_db($database_MyBlogdatabase, $MyBlogdatabase);
  $Result1 = mysql_query($insertSQL, $MyBlogdatabase) or die(mysql_error());

  $insertGoTo = "../index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>記事登録画面</title>
<link href="../css/base.css" rel="stylesheet" type="text/css" media="screen, print" />
</head>
<body>
<h1>Blogシステム管理画面</h1>
<h2>記事登録画面</h2>
<p><a href="index.php">一覧画面にもどる</a></p>
<p>記事の内容を入力して、[登録]ボタンをクリックしてください。</p>
<form id="formMain" name="formMain" method="POST" action="<?php echo $editFormAction; ?>">
<p class="formtitle">タイトル</p>
<p><input name="subject" type="text" id="subject" size="50" maxlength="255" /></p>
<p class="formtitle">内容</p>
<p><textarea name="digest" cols="50" rows="5" id="digest"></textarea></p>
<p class="formtitle">続き</p>
<p><textarea name="document_text" cols="50" rows="20" id="document_text"></textarea>
</p>
<p><input type="submit" name="Submit" value="登録" /></p>
<input type="hidden" name="MM_insert" value="formMain" />
</form>
</body>
</html>


サーバービヘービア → レコード挿入 → forme Main → 値 FORM.doucument_text
移動先はadimn(同じ階層の)index.php(明日記すindex.phpの方)







input.phpをプレビューし、内容を記入し登録


文字化け。


文字化け対処
ConecctionsフォルダーのMy Blog Database.phpの最後にmysql_query("SET NAMES UTF8");を記入









上記の方法でも文字化けが治らない場合は、編集で直接日本語で記入して、再度試してみる。



「entry_id」:「A_I」にチェックするとIDが付く。




昨日の夜からphpMyAdminがエラーをおこし、何も触れられない状況でした。
特にxampの中身も何もいじったこともないので、エラーが起こるのは変だと思い、何度も再起動をしてphpMyAdminに入りましたが、結果はエラーでした。
しかし、今日朝開いてみると、何も問題なく開けました。
時間が解決することもあるんですね(笑)!