用表单编辑Mysql表

时间:2014-02-02 23:06:52

标签: php mysql forms edit

我想使用联系表单编辑mysql数据。当用户在他们想要更改的特定帖子上单击编辑时,它会将他们带到输入字段中具有post值的表单,并且他们可以更改他们想要的关于帖子的任何内容。我已经有了这部分工作但现在我需要更改才能在用户点击提交后实际生效。我怎么能做到这一点?

这是PHP,当用户点击编辑时,它会将mysql中博客帖子中的所有文本显示到输入字段中。

<?php
        include "../php/db_connect.php";

        if (isset($_GET['id'])) {

            $id = $_GET['id'];

            $sql = mysql_query("SELECT * FROM articles WHERE id='$id'");
            while($row = mysql_fetch_array($sql)) {
                $id = $row['id'];
                $title = $row['title'];
                $content = $row['content'];
                $written_by = $row['written_by'];
                $category = $row['category'];
            }

        ?>

    <div class="content_wrapper">
        <h1 class="content_heading">Edit A Blog Post</h1>
        <form method="post" action="php/edit_article_process.php" enctype="multipart/form-data" id="upload_article_form">
            <span>Title</span>
            <input type="text" name="title" class="input" value="<?php echo $title; ?>"/>
            <span>Article</span>
            <textarea rows="20" name="ckeditor1" class="input" style="resize:none;"><?php echo $content ?></textarea>
            <span>Author</span>
            <input type="text" name="written_by" class="input short_input"  value="<?php echo $written_by; ?>"/>
            <span>Category - <i>Spell it right nigga</i></li></span>
            <input type="text" name="category" class="input short_input"  value="<?php echo $category?>"/>
            <input type="submit" name="update" class="input submit_button"/>
        </form>

        <?php } ?>

    </div>

现在我需要的是让更改在用户点击提交时生效。

2 个答案:

答案 0 :(得分:0)

您的form属性method的值为post,这与您在isset()函数中使用的方法不同

您应该使用:

$_GET['id'] //if your method="get"

$_POST['id'] //if your method="post"

答案 1 :(得分:0)

如果您希望更改直接显示,则应在编辑值

后重新刷新页面
header('Location: www.samepage.php');