0

Помогите разобраться с ошибкой Notice: Undefined index: image в переменной $post_image и $post_image_tmp Что не так?

Хочу данные в полях формы, которые извлек из таблицы обновить. Как можно исправить ошибку?

if(isset($_POST['update_post'])){
    $post_author = $_POST['post_author'];
    $post_title = $_POST['post_title'];
    $post_category_id = $_POST['post_category_id'];
    $post_status = $_POST['post_status'];
    $post_image = $_FILES['image']['name'];
    $post_image_temp = $_FILES['image']['tmp_name'];
    $post_content = $_POST['post_content'];
    $post_tags = $_POST['post_tags'];


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

    $query = "UPDATE posts SET";
    $query .= "post_title = '{$post_title}',  ";
    $query .= "post_category_id = '{$post_category_id}', ";
    $query .= "post_date = now(), ";
    $query .= "post_author = '{$post_author}',  ";
    $query .= "post_status = '{$post_status}', ";
    $query .= "post_tags = '{$post_tags}',  ";
    $query .= "post_content = '{$post_content}', ";
    $query .= "post_image = '{$post_image}'  ";
    $query .= "WHERE post_id = {$the_post_id}  ";

    $update_post = mysqli_query($connection, $query);
    // confirm($update_post);
    }


    ?>
    <form action="" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="title">Post Title</label>
            <input type="text" value="<?php echo $post_title; ?>" class="form-control" name="post_title">
        </div>
            <div class="form-group">

      <select name="post_category_id" id="">
        <?php
     $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="author">Post Author</label>
            <input type="text" value="<?php echo $post_author; ?>" class="form-control" name="post_author">
        </div>
        <div class="form-group">
            <label for="post_status">Post Status</label>
            <input value="<?php echo $post_status; ?>" type="text" class="form-control" name="post_status">
        </div>
            <div class="form-group">
            <img width="300"  src="../images/<?php echo $post_image; ?>" alt="" >

        </div>
            <div class="form-group">
            <label for="post_tags">Post Tags</label>
            <input value="<?php echo $post_tags; ?>" type="text" class="form-control" name="post_tags">
        </div>
                <div class="form-group">
            <label for="post_content">Post Content</label>
         <textarea  class="form-control" name="post_content" id="" cols="30" rows="10">
         <?php echo $post_content; ?>
         </textarea>
        </div>
        <div class="form-group">
            <input type="submit" class="btn btn-primary" name="update_post" value="Update Post">
        </div>
    </form>

1 ответ 1

1

Либо я не вижу, либо у тебя нет input`a в форме, который принимает эту самую картинку. Поэтому переменная пуста.

//что бы добавить нужен инпут
<input name="image" type="file" />

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.