Jump to content

Undefined image array key that has been defined


Recommended Posts

I'm getting an undefined array key warning from an array key that has been defined like the other keys in the array.

The method call is as follows:

            $_POST['title'], $_POST['content'], $_POST['category'], 
            $_POST['status'], $_POST['post_type'], $_POST['tags'], $_POST['post_image']

The method and class are:

class Post {
        private $conn;
        private $user_obj;

        public function __construct($conn, $user) {
            $this->conn = $conn;
            $this->user_obj = new User($conn, $user);


        public function addNews($title, $content, $category, $status, $type, $tags, $image) {
            if(!empty($title) && !empty($content)) {
                $title = strtoupper($title);
                $title = mysqli_real_escape_string($this->conn, $title);
                $content = nl2br($content);
                $content = mysqli_real_escape_string($this->conn, $content);
                $added_by = $this->user_obj->getUsername();
                $query = mysqli_query($this->conn, "SELECT top_cat_id FROM top_categories WHERE top_cat_title='$category'");
                $row = mysqli_fetch_array($query);
                $cat_id = $row['top_cat_id'];

                $insert_sql = mysqli_query($this->conn, "INSERT INTO news VALUES ('', '$title', '$content', '$added_by', '$category', '$cat_id', '$image', '$tags', '$status', '$type', '0', '0', '0', '0');");

the relevant HTML is:

<div class="form-group">
    <input type="file" name="post_image" accept="image/*" onchange="preview_image(event)" value="Choose Image">
    <label>Image Preview</label><br>
    <img class="img-rounded" id="output_image" width="150" height="150" />

The warning is an undefined array key on 'post_image'. But it's been defined like all the others. There's nothing I could find relevant to this and I'm lost. Is the problem because it's an image? I see no reason why 'post_image' remains undefined. If anyone feels like looking it over, I always appreciate the extra direction, I'm lost on this

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.