如何避免php转义字符串在线托管


How to avoid php escape string on online hosting?

当我键入don't时,它会将don''not保存到数据库中。我在wamp离线服务器上测试了代码,它保存了don。但当我在在线托管上测试代码时,它会保存don''t。如何使在线托管不使用excape字符串?

代码:

<?php
if (isset($_POST['btn_edit'])) { 
    $description = $_POST['description'];
}

$sql = "UPDATE expense 
    SET description=?
    WHERE spender_id=?";
$q = $conn->prepare($sql);
$result = $q->execute(array($description, $_SESSION['user_id']));
?>
<input type="text" name="description" size="70" value="" />

听起来你的主机已经激活了Magic Quotes。请参阅有关如何禁用它们的手册:http://php.net/magic_quotes

禁用magic_qoutes或更改此语句
  $description = $_POST['description'];

作为

  $description = stripslashes($_POST['description']);