2013年3月6日 星期三

網頁、php、Mysql 中文問題

1.欄位用中文,加上 mysql_query("SET NAMES ‘UTF8′");網頁編碼為big5
取出的欄位名稱會是亂碼;
栽 種 品 :
產 品 品 質 :
備 註:

�W�摨�w_sngdateproductqulmess
1234524212410000-00-00qwdqweqwefgrggh
1243342532352013-01-23
1223312311111110000-00-00
121432132350000-00-00
同樣程式碼,網頁編碼為UTF8




2.欄位名稱用英文,select 使用中文別名,則出現錯誤訊息

mysql_query("SET NAMES ‘UTF8′");
$result=mysql_query("Select p_sn 產品序號 from cut  ");


Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource inC:\AppServ\www\manage\factor\cut.php on line 92


require("../factor/db.php");                     //匯入資料庫設定檔
//require("../彥廷農場/checkform.php");             //匯入欄位檢查檔
//require("../彥廷農場/double.php"); //檢查帳號是否重覆
echo "";



/* 顯示會員資料 */
//mysql_query("SET NAMES ‘UTF8′");
$result=mysql_query("Select * from cut where 產品序號='12345' ");//,order by p_sn desc w_sn B, gdate 日期, product 收穫品, qul 品質, mess 備註

echo "<table border=1>\n"; 
echo "<tr>\n";
/*印出表頭*/
while ($field=mysql_fetch_field($result)) {
echo "<td>".$field->name."</td>\n"; 
}
echo "</tr>\n";
/*印出表身*/
while ($row=mysql_fetch_row($result)) {
echo "<tr>\n";
for ($i=0;$i<count($row);$i++ ){
echo "<td>".$row[$i]."</td>";
}
echo "<tr>\n";
}
?>
<form method="post" action="" accept-charset="big5">
*產 品 序 號 :<input type="text" name="p_sn"><br/> 
*剪蒂人員編號:<input type="text" name="w_sn"><br/>
*日       期:<input type="date" name="gdate" ><br/> 
栽  種  品  :<input type="text" name="product"><br/>
產 品 品 質 :<input type="text" name="qul"><br/> 
備        註:<input type="text" name="mess"><br/> 
<input type="submit" value="新增">
</form>
<?php
require("../factor/db.php");
$p_sn=$_POST['p_sn'];
$w_sn=$_POST["w_sn"];
$gdate=$_POST["gdate"];
$product=$_POST["product"];
$qul=$_POST["qul"];
$mess=$_POST["mess"];

/* 檢查帳號與密碼欄位是否為空白 */
if (empty($p_sn) || empty($w_sn) || empty($gdate))
{
  echo "*號欄位一定要填喔!";
  exit;
}
/* 將欄位資料插入資料庫 */
$sql="INSERT cut (p_sn,w_sn,gdate,product,qul,mess)
VALUES ('$p_sn','$w_sn','$gdate','$product','$qul','$mess')";
mysql_query($sql);
?>


沒有留言:

張貼留言