現在重新整理我的問題(使大家更加容易明白)。 謝謝大家幫忙!! ...
[img align=left width=300]http://viewmorepics.myspace.com/index.cfm?fuseaction-viewImage&friendID=486412357&albumID=234775&imageID=1158610[/img]
在網頁(input.php)上,輸入中文會變空白,輸入英文或數字便正常,輸入中文加英文加數字,全都便為空白,把欄位型態改為varbinary,中文位置變做四方.(如果upload all file to another hosting
co(using MySQl 5), 一齊便正常.
開發工具用ultraedit save as utf8 no bom
我的hosting公司用phpMyAdmin - 2.11.9.5, MySQL 客戶端版本: 4.1.22 , 伺服器版本: 5.0.81-community, MySQL 文字編碼: UTF-8 Unicode (utf8) =>default setting. support PHP 5.29
我全部校對都用utf8_unicode_ci(亦試過全部轉用utf8_general_ci,結果都不成功).
[img align=left width=300]http://viewmorepics.myspace.com/index.cfm?fuseaction-viewImage&friendID=486412357&albumID=234775&imageID=1166629[/img]
[img align=left width=300]http://viewmorepics.myspace.com/index.cfm?fuseaction-viewImage&friendID=486412357&albumID=234775&imageID=1168199[/img]
[img align=left width=300]http://viewmorepics.myspace.com/index.cfm?fuseaction-viewImage&friendID=486412357&albumID=234775&imageID=1170637[/img]
以下是程式的節錄 :
connSchool.php
-----------------------------
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connSchool = "localhost";
$database_connSchool = "xxxx";
$username_connSchool = "xxxx";
$password_connSchool = "xxxx";
$connSchool = mysql_pconnect($hostname_connSchool, $username_connSchool, $password_connSchool) or die(mysql_error());
mysql_query("SET NAMES 'utf8'");
?>
input.php
---------------------------------
<?php header("Content-Type: text/html; charset=utf-8");
require_once('Connections/connSchool.php');
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbteachers (TeacherID, TeacherName, Department) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['TeacherID'], "text"),
GetSQLValueString($HTTP_POST_VARS['TeacherName'], "text"),
GetSQLValueString($HTTP_POST_VARS['Department'], "text"));
$Result1 = mysql_query($insertSQL, $connSchool) or die(mysql_error());
$insertGoTo = "output.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>新增教師資料</title>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″ />
</head>
<body>
<h1>新增教師資料</h1>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table border="0">
<tr>
<td align="right">身分證字號:</td>
<td> <input name="TeacherID" type="text" id="TeacherID" size="10" maxlength="10"></td>
</tr>
<tr>
<td align="right">姓名:</td>
<td> <input name="TeacherName" type="text" id="TeacherName" size="10" maxlength="8"></td>
</tr>
<tr>
<td align="right">系所:</td>
<td> <input name="Department" type="text" id="Department" size="20" maxlength="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="新增資料">
<input type="reset" name="Submit2" value="清除重來"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
output.php
--------------------------------
<?php header( "Content-type: text/html; charset=utf-8");
require_once('Connections/connSchool.php');
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_rsTable = 20;
$pageNum_rsTable = 0;
if (isset($HTTP_GET_VARS['pageNum_rsTable'])) {
$pageNum_rsTable = $HTTP_GET_VARS['pageNum_rsTable'];
}
$startRow_rsTable = $pageNum_rsTable * $maxRows_rsTable;
mysql_select_db($database_connSchool, $connSchool);
$query_rsTable = "SELECT * FROM tbteachers";
$query_limit_rsTable = sprintf("%s LIMIT %d, %d", $query_rsTable, $startRow_rsTable, $maxRows_rsTable);
$rsTable = mysql_query($query_limit_rsTable, $connSchool) or die(mysql_error());
$row_rsTable = mysql_fetch_assoc($rsTable);
if (isset($HTTP_GET_VARS['totalRows_rsTable'])) {
$totalRows_rsTable = $HTTP_GET_VARS['totalRows_rsTable'];
} else {
$all_rsTable = mysql_query($query_rsTable);
$totalRows_rsTable = mysql_num_rows($all_rsTable);
}
$totalPages_rsTable = ceil($totalRows_rsTable/$maxRows_rsTable)-1;
$queryString_rsTable = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsTable") == false &&
stristr($param, "totalRows_rsTable") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsTable = "&" . implode("&", $newParams);
}
}
$queryString_rsTable = sprintf("&totalRows_rsTable=%d%s", $totalRows_rsTable, $queryString_rsTable);
?>
<html>
<head>
<title>瀏覽教師資料表</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<h1>瀏覽教師資料表</h1>
<table border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
<tr>
<td>身分證字號</td>
<td>姓名</td>
<td>科系</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsTable['TeacherID']; ?></td>
<td><?php echo $row_rsTable['TeacherName']; ?></td>
<td><?php echo $row_rsTable['Department']; ?></td>
</tr>
<?php } while ($row_rsTable = mysql_fetch_assoc($rsTable)); ?>
</table>
<p> 記錄 <?php echo ($startRow_rsTable + 1) ?> - <?php echo min($startRow_rsTable + $maxRows_rsTable, $totalRows_rsTable) ?> 共 <?php echo $totalRows_rsTable ?> 筆
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"> <?php if ($pageNum_rsTable > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsTable=%d%s", $currentPage, 0, $queryString_rsTable); ?>">第一頁</a>
<?php } // Show if not first page ?> </td>
<td width="31%" align="center"> <?php if ($pageNum_rsTable > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsTable=%d%s", $currentPage, max(0, $pageNum_rsTable - 1), $queryString_rsTable); ?>">上一頁</a>
<?php } // Show if not first page ?> </td>
<td width="23%" align="center"> <?php if ($pageNum_rsTable < $totalPages_rsTable) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsTable=%d%s", $currentPage, min($totalPages_rsTable, $pageNum_rsTable + 1), $queryString_rsTable); ?>">下一頁</a>
<?php } // Show if not last page ?> </td>
<td width="23%" align="center"> <?php if ($pageNum_rsTable < $totalPages_rsTable) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsTable=%d%s", $currentPage, $totalPages_rsTable, $queryString_rsTable); ?>">最後一頁</a>
<?php } // Show if not last page ?> </td>
</tr>
</table></p>
</body>
</html>
<?php
mysql_free_result($rsTable);
?>