문제

나는 mysqli_real_escape_string ()에 대해 약간의 독서를 해왔고, 콘텐츠를 제대로 탈출 한 후 다시 꺼낼 때 제대로 표시되는 데 어려움이 있습니다.

여기에 내가 가진 코드는 다음과 같습니다.

function update_section_content() {
    $name = mysqli_real_escape_string($this->conn, $_POST['name']);
    $text = mysqli_real_escape_string($this->conn, $_POST['content']);

    // First, we do an update
    $update_query = "UPDATE sections SET content = ? WHERE name = ?";
    if($update_stmt = $this->conn->prepare($update_query)) {
        $update_stmt->bind_param('ss', $text, $name);
        $update_stmt->execute();
        // If the update was successful, read in what we just updated
        if($update_stmt->affected_rows == 1) {
            $read_query = "SELECT content FROM sections WHERE name = ?";
            if($read_stmt = $this->conn->prepare($read_query)) {
                $read_stmt->bind_param('s', $name);
                    $read_stmt->execute();
                $read_stmt->bind_result($content);
                if($read_stmt->fetch()) {
                    echo nl2br($content);
                }
            }
        }
        $read_stmt->close();
        $update_stmt->close();
}

다음 코드에 대한 나의 희망은 레코드를 업데이트하고 나쁜 캐릭터를 피한 다음 성공시 업데이트 된 쿼리를 읽고 이전 시각적 무결성을 유지하기를 원했습니다. (즉, Textarea를 원합니다.

불행히도, 현재로서는 탈출 후에도 여전히 Newline 캐릭터가 표시됩니다. 내가 무엇을 놓치고 있습니까?

시간을 내 주셔서 감사합니다. 제공된 조언은 대단히 감사합니다.

불행히도, 그것은 사실이 아닙니다. 나는 여전히 Newline 캐릭터를 얻습니다

도움이 되었습니까?

해결책

준비된 진술을 사용하고 있으므로 문자열도 피해서는 안됩니다.

문자열 이스케이프는 값을 SQL 쿼리 문자열 자체에 포함시킬 때 이루어 지지만 준비된 진술을 사용하면 그렇게하지 않을 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top