請問mysql資料庫中為何無法存入中文@@?

edited 十月 2013 in 資料庫
我用的是UTF8編碼

當英文或數字存入時都可以正常顯示
但當輸入中文時就是空白
並且無法顯示出來也不是亂碼
試過big5但似乎不用utf8較好
不知道是mysql的問題還是我程式碼的問題
煩請高手幫忙一下

此為SQLCONNECTION
<?php
/* Connecting, selecting database */
$link = mysql_connect('localhost','root','chou')
or doe("Could not connect :" . mysql_error());
//echo "Connected successfully";
mysql_select_db("project") or die("Could not select database");
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER_SET_CLIENT=utf8;");
mysql_query("SET CHARACTER_SET_RESULTS=utf8;");

?>
此為寫入資料庫的程式

<?
if($_POST=='' or $_POST==''
or $_POST=='' or $_POST=='' or
$_POST=='' or $_POST==''
or $_POST=='' ){
my_msg("欄位不可空白","register2.php");
}
$registerid = $_COOKIE["registerid_cookie"];
$fir_name = $_POST;
$sec_name = $_POST;
$nickname = $_POST;
$municipality = $_POST;
$complexarea = $_POST;
$homephone = $_POST;
$mobilephone = $_POST;
$sex = $_POST;
$graduate = $_POST;
$company = $_POST;
$marriage = $_POST;
$sqlstr="insert into member_info (m_id,m_fir_name,m_sec_name,m_nickname,m_municipality
,m_complexarea,m_homephone,m_mobilephone,m_sex,m_graduate,m_company,m_marriage)values(
'$registerid','$fir_name','$sec_name','$nickname','$municipality','$complexarea',
'$homephone','$mobilephone','$sex','$graduate','$company','$marriage')";
$result = mysql_query($sqlstr,$link);
my_msg("新增使用者成功,請以此使用者帳號/密碼重新登入","member.php");
mysql_free_result($result);
mysql_close($link);

?>

附上html
<title>無標題文件</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="register2_chk.php">
<p> </p>
<p>會員基本資料</p>
<p>會員姓/名
<label>
<input name="m_fir_name" type="text" id="m_fir_name" size="15" />
/
<input name="m_sec_name" type="text" id="m_sec_name" size="15" />
</label>
</p>
<p>會員暱稱
<label>
<input name="m_nickname" type="text" id="m_nickname" size="30" />
</label>
</p>
<p>會員地址
<label>
<select name="m_municipality" id="m_municipality">
<option value="台北市">台北市</option>
<option value="台北縣">台北縣</option>
<option value="桃園縣">桃園縣</option>
<option value="新竹縣">新竹縣</option>
<option value="苗栗縣">苗栗縣</option>
<option value="台中縣">台中縣</option>
<option value="彰化縣">彰化縣</option>
<option value="南投縣">南投縣</option>
<option value="雲林縣">雲林縣</option>
<option value="嘉義縣">嘉義縣</option>
<option value="台南縣">台南縣</option>
<option value="高雄縣">高雄縣</option>
<option value="高雄市">高雄市</option>
<option value="屏東縣">屏東縣</option>
<option value="台東縣">台東縣</option>
<option value="花蓮縣">花蓮縣</option>
<option value="宜蘭縣">宜蘭縣</option>
<option value="澎湖縣">澎湖縣</option>
</select>
</label>
<label>
<input name="m_complexarea" type="text" id="m_complexarea" value="" size="80" />
</label>
</p>
<p>聯絡電話
<label>
<input name="m_homephone" type="text" id="m_homephone" />
</label>
</p>
<p>行動電話
<label>
<input name="m_mobilephone" type="text" id="m_mobilephone" />
</label>
</p>
性別
<label>
<input name="m_sex" type="radio" value="radiobutton" checked="checked" />

<input name="m_sex" type="radio" value="radiobutton" />
</label>

<p>學歷
<label>
<select name="m_graduate" id="m_graduate">
<option>國中/小</option>
<option>高中/職</option>
<option>大學/專</option>
<option>碩士</option>
<option>博士</option>
</select>
</label>
</p>
<p>公司/學校名稱
<label>
<input name="m_company" type="text" id="m_company" />
</label>
</p>
<p>婚姻狀況
<label>
<input name="m_marriage" type="radio" value="radiobutton" checked="checked" />
</label>
已婚
<label>
<input name="m_marriage" type="radio" value="radiobutton" />
</label>
未婚</p>
<p>
<label>
<input type="submit" name="Submit" value="送出" />
</label>
<label>
<input type="reset" name="Submit2" value="重設" />
</label>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form>
</body>
</html>


原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=4523

評論

Sign In or Register to comment.