如何更新这种形式的所有数据?

时间:2018-06-23 21:33:28

标签: php web web-deployment web-deployment-project

这是PHP中的一个系统,用于保存数据库中的“类别”信息。我实现了删除但更新查询不起作用,有人可以帮助我找出错误吗?

下面的代码是

<?php // ob_start(); ?>
<?php
    if (isset($_GET['update'])) {
        $post_id = $_GET['update'];
        $query = "select * from posts where post_id = {$post_id}";
        $select_categories = mysqli_query($connection, $query);

        while ($row = mysqli_fetch_assoc($select_categories)) {
            $post_id = $row['post_id'];
            $post_category_id = $row['post_category_id'];
            $post_title = $row['post_title'];
            $post_author = $row['post_author'];
            $post_date = $row['post_date'];
            $post_image = $row['post_image'];
            $post_content = $row['post_content'];
            $post_tags = $row['post_tag'];
            $post_comment_count = $row['post_comment_count'];
            $post_status = $row['post_status'];
        }
    }
?>

<?php
    if (isset($_POST['subs'])) {
        $post_authors = $_POST['post_author'];
        $post_statuss = $_POST['post_status'];
        $post_tagss = $_POST['post_tags'];
        $post_contents = $_POST['post_content'];
        $post_titles = $_POST['post_title'];
        $post_category = $_POST['post_category'];
        $post_images = $_FILES['image']['name'];
        $post_image_temp = $_FILES['image']['tmp_name'];

        move_uploaded_file($post_image_temp, "../image/$post_image");

        $queries = "update posts set post_category_id = '{$post_category}' post_title = '{$post_titles}', post_author = '{$post_authors}', post_date = now(), post_image = '{$post_image}', post_content = '{$post_contents}', post_tag='{$post_tags}', post_comment_count='{$post_comment_count}', post_status = '{$post_status}' where post_id = {$post_id}";

        $update_post = mysqli_query($connection, $queries);

        if (!$update_post)
            echo "Stupid";
    }
?>

<form action="posts.php" method="post" enctype="multipart/form-data">

    <div class="form-group">
        <label for="title">Post title</label>
        <input value="<?php if (isset($post_title)){ echo $post_title;} ?>" type="text" class="form-control" name="post_title">
    </div>

    <div class="form-group">
        <label for="title">Post Category Id</label>
        <br>
        <select name="post_category" id=""> <!-- post_category is the one that takes the value -->
        <?php
        if (isset($_GET['update'])) {
            $cat_ids = $_GET['update'];
            $query = "select * from categories";
            $select_categories = mysqli_query($connection, $query);

            confirm($select_categories);

            while ($row = mysqli_fetch_assoc($select_categories)) {
                $cat_id = $row['cat_id'];
                $cat_title = $row['cat_title'];

                echo "<option value='{$cat_id}'>{$cat_title}</option>";
            }
        }
        ?>
        </select>

    </div>

    <div class="form-group">
        <label for="title">Post Author</label>
        <input value="<?php if (isset($post_author)){ echo $post_author;} ?>" type="text" class="form-control" name="post_author">
    </div>

    <div class="form-group">
        <label for="title">Post Status</label>
        <input value="<?php if (isset($post_status)){ echo $post_status;} ?>" type="text" class="form-control" name="post_status">
    </div>

    <div class="form-group">
        <label for="title">Post Image</label>
        <img width="100" src="../images/<?php echo $post_image; ?>" alt="">
        <input type="file" name="image">
    </div>

    <div class="form-group">
        <label for="title">Post Tags</label>
        <input value="<?php if (isset($post_tags)){ echo $post_tags;} ?>" type="text" class="form-control" name="post_tags">
    </div>

    <div class="form-group">
        <label for="title">Post Content</label>
        <textarea class="form-control" name="post_content" id="" cols="30" rows="10"><?php if (isset($post_content)){ echo $post_content;} ?></textarea>
    </div>

    <div class="form-group">
        <input class="btn btn-primary" type="submit" name="subs" value="Update">
    </div>

</form> 

Works: 1.一键删除链接

  1. 将从数据库中提取表单,所有值将显示在特定字段上

  2. 用户可以更新

  3. 一旦单击“更新”按钮,这些值将被推回到db。.

请帮助我进行更新。.

1 个答案:

答案 0 :(得分:0)

您缺少逗号。

'{$post_category}' post_title =

'{$post_category}' ,  post_title =