简体   繁体   中英

How can I save image and text from tinymce editor into database?

I make a text editor by using tinymce. Normally, everything is fine when I try to save only text into database.

Here is my code.

<script>
    tinymce.init ({
        selector: "#q_box",
        theme: "modern",
        plugins: [
            "advlist autolink lists link image charmap print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen",
            "insertdatetime media nonbreaking save table contextmenu directionality",
            "emoticons template paste textcolor colorpicker textpattern imagetools"
        ],
        toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        toolbar2: "print preview media | forecolor backcolor emoticons",
        image_advtab: true,
        templates: [
            {title: 'Test template 1', content: 'Test 1'},
            {title: 'Test template 2', content: 'Test 2'}
        ]
    });
</script>
<?php
include("connect.php");
if(isset($_POST['post_btn'])) {
    $title = $_POST['p_title'];
    $post  = $_POST['q_box'];

    if(!empty($title) && !empty($post)) {
        $query = "insert into course(post_title,post_page)values('$title','$post')";
        $success = mysql_query($query) or die("Query error");
     }
}
?>
<form id="write" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    <input type="text" id="p_title" name="p_title" placeholder="Post Title" autofocus/>
    <br/>
    <textarea name="q_box" id="q_box"></textarea></p>
    <label for="label">Label:</label>
    <input type="submit" value="Post" name="post_btn" id="post_btn" />
</form>

But now, I want to save not only text but also image and video into database.

When I try to save image or video with the above code. The image/video is not show correctly. It shows like this

图片

I'm not sure my code is right or wrong. I don't never used tinymce editor before.

The main point what I want is, I want to save image, video and text as I formatted in tinymce into database and I want to show that formatted text and image again into my webpage.

Try to use this when you post variables :

$title = addslashes($_POST['p_title']);
$post  = addslashes($_POST['q_box']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM