-2

Notice: Undefined index: post_catagory in /Users/darceymckelvey/Desktop/php/includes/classinsert.php on line 9

Notice: Undefined variable: category in /Users/darceymckelvey/Desktop/php/includes/classinsert.php on line 13

The code:

<?php
  require_once('classdb.php');

  if(!class_exists('INSERT')){
    class INSERT {
      public function post($postdata){
        global $db;

        $catagory = serialize($postdata['post_catagory']);

        $query = "
                  INSERT INTO posts(post_title, post_content, post_category)
                  VALUES ('$postdata[post_title]', '$postdata[post_content]', '$category')
              ";

        return $db->insert($query);
      }
    }
  }

  $insert = new INSERT;
?>

Issue:

The outputted result is the post_title and post_content working but the post_category not at all and is left blank.

J.K
  • 1,382
  • 1
  • 11
  • 27
Darcey Mckelvey
  • 546
  • 2
  • 8
  • 20
  • 2
    Well your `$postdata` array doesn't have an index called `post_category`. Do `print_r($postdata);` to see what you have in your array. – Rizier123 Apr 26 '16 at 07:17
  • 2
    there's a typo mistake : `$category` in query and your variable `$catagory`, please check it @Darcey Mckelvey – Nehal Apr 26 '16 at 07:23

1 Answers1

1

You are making a mistake, there's typo issue in your code, because of which you are not getting category values.

Try this code :

<?php
  require_once('classdb.php');

  if(!class_exists('INSERT')){
    class INSERT {
      public function post($postdata){
        global $db;

        $category = serialize($postdata['post_category']);

        $query = "
                  INSERT INTO posts(post_title, post_content, post_category)
                  VALUES ('$postdata['post_title']', '$postdata['post_content']', '$category')
              ";

        return $db->insert($query);
      }
    }
  }

  $insert = new INSERT;
?>
A.L
  • 10,259
  • 10
  • 67
  • 98
Nehal
  • 1,542
  • 4
  • 17
  • 30