我有一個簡單的HTML表單,用POST函數提交信息。但是當信息包含一個西里爾文字符時,在MySql中的表格中就會變成ааааза符號而不是文本。該表位於utf-8_general_ci上,該網站使用UTF-8編碼。我想象這個表的結果與POST與SQL函數編碼問題的簡單HTML表單?
$query = "
SELECT ".$db->nameQuote('ingredients')."
FROM ".$db->nameQuote('other')."
ORDER by id DESC
";
$db->setQuery($query);
$ingredients = $db->loadResult();
我不能理解如何告訴窗體發送正確的字體。或者問題在哪裏?如何正確獲取這些字符?或者如何正確發送它們?
-----------------編輯-----------------------
我不明白哪裏放
mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8");
所以我在這裏貼上我的代碼。首先,簡單的形式:
<form action="insert.php" method="post" onsubmit="return checkForm(this)" target="_top">
<table>
<tr>
<td colspan="2">
<ul>
<li> Добавете необходимите за рецептата съставки</li>
<li> Моля попълнете всички полета коректно</li>
<li> Полетата маркирани с (*) са задължителни</li>
</ul>
</td>
</tr>
<tr>
<td>
Количество (порции)*:
</td>
<td>
<input type="text" name="quantity" />
</td>
</tr>
<tr>
<td>
Съставки*:
</td>
<td>
<input type="text" name="ingredients" />
</td>
</tr>
<tr>
<td>
Време за приготвяне*:
</td>
<td>
<input type="text" name="timing" /><br />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Напред" class="button validate" />
</td>
</tr>
</table>
</form>
而且我insert.php文件中的取語法:
$query = "
SELECT ".$db->nameQuote('quantity')."
FROM ".$db->nameQuote('other')."
ORDER by id DESC
";
$db->setQuery($query);
$quantity = $db->loadResult();
$query = "
SELECT ".$db->nameQuote('ingredients')."
FROM ".$db->nameQuote('other')."
ORDER by id DESC
";
$db->setQuery($query);
$ingredients = $db->loadResult();
$query = "
SELECT ".$db->nameQuote('timing')."
FROM ".$db->nameQuote('other')."
ORDER by id DESC
";
$db->setQuery($query);
$timing = $db->loadResult();
你的查詢不能只是'$ query =「選擇數量,成分,時間從其他訂單編號DESC」;'? – 2010-06-06 20:35:27
$ db-> setQuery('SET CHARACTER SET utf8; SET NAMES utf8;'); $ db-> loadResult(); (如果這不起作用,請分別發出命令) – Robus 2010-06-07 17:25:59