简体   繁体   English

使用ck编辑器更新后页面未重定向

[英]Page is not redirecting after update with ck editor

Im using CK editor. 我正在使用CK编辑器。 For database Im using mysql. 对于使用MySQL的数据库Im。 But when i click on the submit button to submit the form the database is updating but the page is not redirecting to a different location. 但是,当我单击“提交”按钮提交表单时,数据库正在更新,但是页面未重定向到其他位置。

  <?php 



  $sql="select * from automation_full";
  $query=mysql_query($sql_get);
  $row=mysql_fetch_object($query_get);
  $old_content=$row->column1;

  if(isset($_POST['save']))
  {
    $new_content=$_POST['content'];

    $sql="update table1 set content='$new_content' where key_id=1";
    $query=mysql_query($sql);

    if($query)
        {
            header("Location:index.php");
        }

  }


  ?>

    <div class="custom-container-right-form">



        <form action="#" method="post">


            <textarea id="text" name="content"></textarea>
             <script>
                CKEDITOR.replace( 'content' );
            </script>

            <input type="submit" id="submit-button" name="save" value="Update">


        </form>

    </div> 

When i click on save it should update table1 and redirect to index.php . 当我单击保存时,它应该更新table1并重定向到index.php。 but my program is updating the table but not redirecting to index.php ... But when Im not using ck editor it works perfectly ok.... how to make it work with ck editor? 但是我的程序正在更新表,但没有重定向到index.php ...但是当我不使用ck编辑器时,它工作得很好....如何使其与ck编辑器一起工作?

Change the textarea id as per your field name as: 根据您的字段名称将textarea id更改为:

<textarea id="content" name="content"></textarea>
<script>
    CKEDITOR.replace( 'content' );
</script>

add die() or exit() 添加die()或exit()

Since die() or exit() after your 由于die()或exit()在您之后

 header('Location:http://something') 

prevent it from resulting in unexpected behaviour. 防止导致意外行为。

if($query)
        {
            header("Location:index.php");
            die();
        }

How about echoing <script>location.href=/page.php</script> instead of the php header? 如何回显<script>location.href=/page.php</script>而不是php标头? That only allows for redirection when no other content has been outputted, while this option redirects, no matter what, as soon as it gets written to the document. 仅当没有其他内容输出时,才允许重定向,而无论此选项是什么,只要将其写入文档,便会进行重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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