dongrong7267 2013-01-15 23:12
浏览 24
已采纳

数据库中未正确保存的字符

I am not sure if this is because of jquery, mysql or php

I have a basic AJAX call:

$(document).on("click", "#save-edit", function(){
    var id = $(this).closest("div.answer-section").attr("data-id");
    $.ajax({
        type: "post",
        data: {
            id: id,
            answer: $("#edit-box").val()
        },
        url: "/process/edit",
        dataType: "json",
        success: function(data){
            // display the data
        }
    });
});

and a basic SQL query:

$sql = $pdo->prepare("update answers set answer = :answer where answer_id = :aid");
$sql->bindParam("answer", $_POST["answer"], PDO::PARAM_STR);
$sql->bindParam("aid", $_POST["id"], PDO::PARAM_INT);
$sql->execute();

The problem I am having is, it saves characters like this: é é in the database as this é é then displays é é on the page, so what is causing this, the JQuery, or the MySQL or the PHP? How can I fix it?

  • 写回答

1条回答 默认 最新

  • dongzhenbi8919 2013-01-15 23:23
    关注

    Well I found the answer, every thing is fine, just needed to add this to the HTML header:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据