【问题标题】:MySQL PHP - Can't update textMySQL PHP - 无法更新文本
【发布时间】:2017-03-19 23:09:52
【问题描述】:

表 user_content 具有列 id、context_text、email_last_edit。

这是我的更新方法:

$content_text1 = utf8_decode($_POST['content_text1']);
$conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn->connect_error) {
    die("Datenbankverbindung fehlerhaft: " . $conn->connect_error);
  }

  $sql = 'UPDATE user_content SET content_text="' . $content_text1 . '" AND email_last_edit="' . $email . '" WHERE id=1';

  if ($conn->query($sql) === TRUE) {

    //echo "New record created successfully";

  } else {

    echo "Datenbank-Fehler: " . $sql . "<br>" . $conn->error;

  }

  $conn->close();

我通过 post 将此文本发送到同一个 php 页面:

<h1><b>Mitglied</b></h1><br><b>Community</b>
<b>Kurzprofil</b>,ß<b>Community-Bereich</b<b>Chats</b>.

不幸的是,每次更新列 content_text 都会变为 0。 我认为这是文本中特殊字符的问题,但 uft8_decode() 无论如何都无法解决此问题。

有人知道这个问题的解决方案吗? 非常感谢:)

【问题讨论】:

标签: php mysql database utf-8


【解决方案1】:

通过

更改您的查询
$sql = 'UPDATE user_content SET content_text="' . $content_text1 . '" , email_last_edit="' . $email . '" WHERE id=1';

删除“AND”并替换为“,”

出于安全原因,您也必须转义参数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多