dongmei8460 2013-10-23 19:06
浏览 33
已采纳

PDO bindParam更改我的字符串

I've the following code to insert some data into my database:

$query = "INSERT INTO `questions`(`title`,`content`,`set`,`date`) VALUES(:title,:content,:set,:date)";
    $stmt = $db -> prepare($query);
    $stmt -> bindParam(':title',$title,PDO::PARAM_STR);
    $stmt -> bindParam(':content',$content,PDO::PARAM_STR);
    $stmt -> bindParam(':set',$set,PDO::PARAM_INT);
    $stmt -> bindParam('date',$date,PDO::PARAM_STR);
    $stmt -> execute();
    echo '<script>alert("שאלה נוספה בהצלחה");</script>';

The problem is, whenever I view the inserted information in the DB, it turns to weird string such as: &#1489;&#1506;&#1489;&#1512;&#1497;&#1514; I have no clue why it's happening!

P.S. If I insert English string, it's all right. It shows as a proper english in the DB. It happens when I insert data in my language.

  • 写回答

4条回答 默认 最新

  • douna2633 2013-10-24 13:16
    关注

    After inspecting it for a while, I found out what was the problem.

    The form that I got the input from wasn't inside an HTML tags because it was a quick and very simple interface.

    After giving that a thought, I tried to do the form inside proper HTML tags. I've enclosed the <form> tag in this:

        <html dir="rtl">
        <head>
        <title>Insert a new question</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> // important line
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      </head>
     <body>
    <!-- form here -->
    </body>
    </html
    

    After doing that, the input given was a proper Hebrew letters instead of the HTML entity code.

    Hope this will help someone.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?