Ckeditor:除了<textarea>之外还保存数据

问题描述 投票:0回答:1

我尝试使用Ckeditor进行项目。现在可以将<textarea>添加到数据库中,但是当我尝试添加<input>标记时,如下所示,我无法保存它。只有<textarea>保存在数据库中:

                <div class="form-group"> 
                    <label for="exampleInputEmail1">Name</label>
                    <input type="text" name ="text" class="form-control" id="name"  placeholder="Name">
                </div>


                <div class="form-group"> 
                    <label for="exampleInputEmail1">Editor</label>
                    <textarea name ="text" class="form-control" id="text" rows="3" placeholder="Textarea"></textarea>
                </div>
                 <input type="submit" class="btn btn-primary" name="submit" value ="Submit">
            </form>

这是Php:

 <?php 


                if (isset($_POST['submit'])) 
                {   
                    $text=$_POST['text'];
                    $name=$_POST['name'];
                    $con=mysqli_connect('localhost','root','','ckeditor') or die(ERROR);
                    $query=mysqli_query($con,"INSERT INTO content(content,author) VALUES ('$text','$name')");


                    if($query==1)  
                           {  
                            echo "<script>
                        window.location.href='./ask_question.php';
                        alert('Success');

                        </script>";
                          exit;
                           }  
                        else  
                           {  
                              echo'<script>alert("Failed To Insert")</script>';  
                           }  



                }
                ?>
php ckeditor ckeditor4.x
1个回答
0
投票

这是因为你在两个元素中都复制了name属性("text")。在提交表单时,使用name而不是id

稍作修改就足够了:

            <div class="form-group"> 
                <label for="exampleInputEmail1">Name</label>
                <input type="text" name="name" class="form-control" id="name"  placeholder="Name">
            </div>


            <div class="form-group"> 
                <label for="exampleInputEmail1">Editor</label>
                <textarea name ="text" class="form-control" id="text" rows="3" placeholder="Textarea"></textarea>
            </div>
             <input type="submit" class="btn btn-primary" name="submit" value ="Submit">
        </form>
© www.soinside.com 2019 - 2024. All rights reserved.