how to insert HTML code into DB using php

前端 未结 6 2009
故里飘歌
故里飘歌 2020-12-11 12:40

i want to update my database with new html code this it the query:

UPDATE `Pages` SET `content`= \'
相关标签:
6条回答
  • 2020-12-11 12:56

    Do following using addslashes() function, so it will help easily to insert update html to

    UPDATE `Pages` SET `content`= addslashes('<div id="intro">
    <div id="about" align="left">
    <h2 class="bigHeader" dir="rtl"HEADER</h2>
    <img src="img/Med-logo.png" alt="" />
    <div id="wellcomePage" class="text-left text" dir="rtl">
    <p>...some words....</p>
    <p>.some words....</p>
    <p>&nbsp;</p>
    </div>
    </div>
    </div>') 
    
    0 讨论(0)
  • 2020-12-11 13:00

    This could be duplicate of this post

    in any case... this could be the solution for you

    $html = mysql_real_escape_string($html);
    $sql = "UPDATE `Pages` SET `content`= $html";
    
    0 讨论(0)
  • I think there should be a (') single Quote into your string.

    You can use the 'htmlspecialchars' function with ENT_QUOTES as second argument.

    And also 'mysql_real_escape_string' function can be used.

    Like

    $hcode = '<div id="intro">
    <div id="about" align="left">
    <h2 class="bigHeader" dir="rtl"HEADER</h2>
    <img src="img/Med-logo.png" alt="" />
    <div id="wellcomePage" class="text-left text" dir="rtl">
    <p>...some words....</p>
    <p>.some words....</p>
    <p>&nbsp;</p>
    </div>
    </div>
    </div>';
    $hcode = htmlspecialchars($hcode, ENT_QUOTES);
    UPDATE `Pages` SET `content`= '$hcode';
    
    0 讨论(0)
  • 2020-12-11 13:04

    Try this:- $htmlcode = mysql_real_escape_string($htmlcode);

    For example:-

    $htmlcode = '<div id="intro">
    <div id="about" align="left">
    <h2 class="bigHeader" dir="rtl"HEADER</h2>
    <img src="img/Med-logo.png" alt="" />
    <div id="wellcomePage" class="text-left text" dir="rtl">
    <p>...some words....</p>
    <p>.some words....</p>
    <p>&nbsp;</p>
    </div>
    </div>
    </div>';
    
    $htmlcode = mysql_real_escape_string($htmlcode);
    
    UPDATE `Pages` SET `content`= '$htmlcode';
    
    0 讨论(0)
  • 2020-12-11 13:11

    store your html content in one variable and use addslashes() when you are inserting it to database.

    $content='<div id="intro">
    <div id="about" align="left">
    <h2 class="bigHeader" dir="rtl"HEADER</h2>
    <img src="img/Med-logo.png" alt="" />
    <div id="wellcomePage" class="text-left text" dir="rtl">
    <p>...some words....</p>
    <p>.some words....</p>
    <p>&nbsp;</p>
    </div>
    </div>
    </div>';
    

    and write your query as below

    UPDATE `Pages` SET `content`=addslashes($content);
    

    Hope this will help you :)

    0 讨论(0)
  • 2020-12-11 13:12

    I assume this will do the trick

    Encode your text

    when you get the text back from the database just decode it back

    0 讨论(0)
提交回复
热议问题