0

I'm trying to create an admin side form. Here i'm trying to select data from the database. Also i want to display it. But for some reason it's not working. Here's my controller code,

public function save()
{
  if (Input::has('save'))
  {
    $rules = array('category_name' => 'required|min:1|max:50', 'parent_category' => 'required');
    $input = Input::all();
    $messages = array('category_name.required' =>'Please enter the category name.', 'category_name.min' => 'Category name must be more than 4 characters', 'category_name.max' =>'Category name must not be more than 15 characters!!!',  'parent_category.required' => 'Please Select  Parent Category.',);
    $validator = Validator::make($input, $rules, $messages);

    if ($validator->fails()) 
    {
        return Redirect::to('admin/category/add')->withErrors($validator)->withInput($input); 
    }
    else
    {       
        $insert_db = CategoryModel::insert($input);
        $selected_category = CategoryModel::select($input['category_name']);
    }
  } 
}

and my CategoryModel.php is following.

public static function insert($values)
{
      $insert  = DB::table('add_category')->insert(array('category_name'=>$values['category_name'], 'parent_category'=>$values['parent_category']));
      if(isset($insert))
      { 
        echo 'inserted successfully';
      }  
      else 
      {
        echo 'Failed';
       }        
}

public static function select($values)
{
      $insert = DB::table('add_category')->where('category_name' . '=' . $values['category_name']);
}
2
  • possible duplicate of Error: Illegal String Offset in PHP Commented Aug 5, 2014 at 10:51
  • 1
    can you tell us which file the error is being thrown on? there is a reference to category_name in both files. Commented Aug 5, 2014 at 17:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.