dongyong6045 2010-06-06 19:52
浏览 55
已采纳

简单的HTML表单与POST到SQL函数编码问题?

I have a simple html form that submits information with POST function. But when information contains a Cyrillic characters, in table in MySql there becomes азазаза symbols instead of text. The table is on utf-8_general_ci, the site is on UTF-8 encoding. I visualize the result from this table with

$query = "
  SELECT ".$db->nameQuote('ingredients')."
    FROM ".$db->nameQuote('other')."
    ORDER by id DESC
  ";
$db->setQuery($query);
$ingredients = $db->loadResult();

I cant understand how to tell the form to send chyrillic characters correct. Or where is the problem at all? How to fetch this characters correctly? Or how to send them correctly?

-----------------EDIT-----------------------

I couldn't understand where to put

mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8");

So I'm pasting my code here. First the simple form:

<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>

And the fetching syntax inside my insert.php file:

$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();
  • 写回答

5条回答 默认 最新

  • donglong1465 2010-06-06 20:01
    关注

    Try setting collocation?

     mysql_query("SET CHARACTER SET utf8");
     mysql_query("SET NAMES utf8");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度