0

Here's a system in PHP that holds 'categories' info from data base. I implemented the delete but update query is not working, can any one help me to figure out error?

code is down bellow:

<?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. One clicks delete link

  1. A form will be pulled from DB and all values will be shown on particular field

  2. User may Update

  3. The values will be pushed back to db as soon as 'Update' button is clicked..

Please help me to update..

coder
  • 8,346
  • 16
  • 39
  • 53
java
  • 33
  • 6

1 Answers1

0

You are missing a comma.

'{$post_category}' post_title =

'{$post_category}' ,  post_title =
Bleach
  • 561
  • 4
  • 11