Welcome Guest, Not a member yet? Register   Sign In
Search Criteria Ignored, Only Redirects to Else Statement
#3

(This post was last modified: 06-12-2019, 02:05 PM by Josh1985.)

(06-12-2019, 01:28 PM)jreklund Wrote: If that's the case your problem are here "$this->input->post('submit')", that it gets validated as false.
Just do a double check and add die('Hello'); the first thing inside that if statement.

PHP Code:
function search(){
 if(
$this->input->post('submit')){
 
  die('Hello');
...
 
 }


If you don't see "Hello"; Add var_dump($this->input->post('submit'));exit; before that if and see what you are getting.

ALSO: Your search() code have SQL injections. You should fix that ASAP!

Thank you for your help! That did not work unfortunately.

Original Recipe.php Controller
Code:
<?php
class Recipe extends MY_Controller{

function __construct() {
 parent::__construct();
  $uri = $this->uri->uri_string();
  $this->session->set_flashdata('uri', $uri);
}

function index(){
 $recipe_linkname = $this->uri->rsegment(3);
 if(!$recipe_linkname){
  $recipe_linkname = $this->recipe_model->first_linkname();
 }
 $recipe = $this->recipe_model->read_record($recipe_linkname);
 if(count($recipe) == 0){
  show_404('');
  die();
 }
 $data = array(
    'title' => "Shirley's Recipes : ".$recipe['name'],
  'columns' => array('toc', 'recipe'),
   'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}

function flipbook(){
 $this->require_login();
 $this->load->library('pagination');
   
       $config['base_url'] = site_url('recipe/flipbook');
     $config['total_rows'] = $this->recipe_model->num_rows();
    $config['uri_segment'] = '3';
       $config['per_page'] = 1;
      $config['num_links'] = 1;
  $config['display_pages'] = FALSE;
  $config['full_tag_open'] = '<div id="pagination">';
 $config['full_tag_close'] = '</div>';
 
 $this->pagination->initialize($config);
 $recipe = $this->recipe_model->read_records($config['per_page'], $this->uri->segment(3))->row_array();
   $data = array(
     'title' => "Shirley's Recipes : ".$recipe['name'],
     'columns' => array('toc', 'recipe_flipbook'),
      'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}
 
function search(){
 if($this->input->post('submit')){
   $search = $this->input->post('query');
  $results = $this->recipe_model->search($search);
     $data = array(
     'title' => "Shirley's Recipes : Search Results",
     'columns' => array('toc', 'recipe_search'),
     'recipes' => $results,
  );
  $this->load->view('includes/template', $data);
  }
  else{
   redirect('recipe');
  }
}

function add(){
 $this->require_login();
 if($this->input->post('submit')){
  $data = array(
       'name' => $this->input->post('name'),
 'buttontext' => $this->input->post('buttontext'),
           'linkname' => $this->input->post('linkname'),
                'img' => $this->input->post('img'),
               'time' => $this->input->post('time'),
   'category' => $this->input->post('category'),
        'subcategory' => $this->input->post('subcategory'),
' ingredients' => $this->input->post('ingredients'),
  'equipment' => $this->input->post('equipment'),
'preparation' => $this->input->post('preparation'),
 'directions' => $this->input->post('directions')
  );
  $recipeid = $this->recipe_model->create_record($data);
  redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $data = array(
     'title' => "Shirley's Recipes : Add New Recipe",
   'columns' => array('toc', 'admin/recipe_edit'),
    'recipe' => array('name' => '',
                      'buttontext' => '',
                        'category' => '',
                     'subcategory' => '',
                        'linkname' => '',
                             'img' => '',
                            'time' => '',
                     'ingredients' => '',
                       'equipment' => '',
                     'preparation' => '',
                      'directions' => '')
  );
  $this->load->view('includes/template', $data);
 }
}

function edit(){
 $this->require_login();
 $id = $this->uri->segment(3);
 if($this->input->post('submit')){
  $data = array(
          'name' => $this->input->post('name'),
  'buttontext' => $this->input->post('buttontext'),
    'linkname' => $this->input->post('linkname'),
           'img' => $this->input->post('img'),
           'time' => $this->input->post('time'),
      'category' => $this->input->post('category'),
   'subcategory' => $this->input->post('subcategory'),
   'ingredients' => $this->input->post('ingredients'),
     'equipment' => $this->input->post('equipment'),
   'preparation' => $this->input->post('preparation'),
    'directions' => $this->input->post('directions')
   );
   $this->recipe_model->update_record($id, $data);
   redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $recipe = $this->recipe_model->read_record($id);
  $data = array(
   'title' => "Shirley's Recipes : Edit Recipe : ".$recipe['name'],
   'columns' => array('toc', 'admin/recipe_edit'),
        'id' => $id,
  'recipe' => $recipe
  );
  $this->load->view('includes/template', $data);
 }
}

function delete(){
 $this->require_login();
 $this->recipe_model->delete_record($this->uri->segment(3));
 redirect('/');
}
}
// End - recipe.php
?>

1st Modified Recipe.php Controller
Code:
<?php
class Recipe extends MY_Controller{

function __construct() {
 parent::__construct();
  $uri = $this->uri->uri_string();
  $this->session->set_flashdata('uri', $uri);
}

function index(){
 $recipe_linkname = $this->uri->rsegment(3);
 if(!$recipe_linkname){
  $recipe_linkname = $this->recipe_model->first_linkname();
 }
 $recipe = $this->recipe_model->read_record($recipe_linkname);
 if(count($recipe) == 0){
  show_404('');
  die();
 }
 $data = array(
    'title' => "Shirley's Recipes : ".$recipe['name'],
  'columns' => array('toc', 'recipe'),
   'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}

function flipbook(){
 $this->require_login();
 $this->load->library('pagination');
   
       $config['base_url'] = site_url('recipe/flipbook');
     $config['total_rows'] = $this->recipe_model->num_rows();
    $config['uri_segment'] = '3';
       $config['per_page'] = 1;
      $config['num_links'] = 1;
  $config['display_pages'] = FALSE;
  $config['full_tag_open'] = '<div id="pagination">';
 $config['full_tag_close'] = '</div>';
 
 $this->pagination->initialize($config);
 $recipe = $this->recipe_model->read_records($config['per_page'], $this->uri->segment(3))->row_array();
   $data = array(
     'title' => "Shirley's Recipes : ".$recipe['name'],
     'columns' => array('toc', 'recipe_flipbook'),
      'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}
 
function search(){
if($this->input->post('submit')){
  die('Hello');
   $search = $this->input->post('query');
  $results = $this->recipe_model->search($search);
     $data = array(
     'title' => "Shirley's Recipes : Search Results",
     'columns' => array('toc', 'recipe_search'),
     'recipes' => $results,
  );
  $this->load->view('includes/template', $data);
  }
  else{
   redirect('recipe');
  }
}

function add(){
 $this->require_login();
 if($this->input->post('submit')){
  $data = array(
       'name' => $this->input->post('name'),
 'buttontext' => $this->input->post('buttontext'),
           'linkname' => $this->input->post('linkname'),
                'img' => $this->input->post('img'),
               'time' => $this->input->post('time'),
   'category' => $this->input->post('category'),
        'subcategory' => $this->input->post('subcategory'),
' ingredients' => $this->input->post('ingredients'),
  'equipment' => $this->input->post('equipment'),
'preparation' => $this->input->post('preparation'),
 'directions' => $this->input->post('directions')
  );
  $recipeid = $this->recipe_model->create_record($data);
  redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $data = array(
     'title' => "Shirley's Recipes : Add New Recipe",
   'columns' => array('toc', 'admin/recipe_edit'),
    'recipe' => array('name' => '',
                      'buttontext' => '',
                        'category' => '',
                     'subcategory' => '',
                        'linkname' => '',
                             'img' => '',
                            'time' => '',
                     'ingredients' => '',
                       'equipment' => '',
                     'preparation' => '',
                      'directions' => '')
  );
  $this->load->view('includes/template', $data);
 }
}

function edit(){
 $this->require_login();
 $id = $this->uri->segment(3);
 if($this->input->post('submit')){
  $data = array(
          'name' => $this->input->post('name'),
  'buttontext' => $this->input->post('buttontext'),
    'linkname' => $this->input->post('linkname'),
           'img' => $this->input->post('img'),
           'time' => $this->input->post('time'),
      'category' => $this->input->post('category'),
   'subcategory' => $this->input->post('subcategory'),
   'ingredients' => $this->input->post('ingredients'),
     'equipment' => $this->input->post('equipment'),
   'preparation' => $this->input->post('preparation'),
    'directions' => $this->input->post('directions')
   );
   $this->recipe_model->update_record($id, $data);
   redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $recipe = $this->recipe_model->read_record($id);
  $data = array(
   'title' => "Shirley's Recipes : Edit Recipe : ".$recipe['name'],
   'columns' => array('toc', 'admin/recipe_edit'),
        'id' => $id,
  'recipe' => $recipe
  );
  $this->load->view('includes/template', $data);
 }
}

function delete(){
 $this->require_login();
 $this->recipe_model->delete_record($this->uri->segment(3));
 redirect('/');
}
}
// End - recipe.php
?>
Nothing happened after this. It returned the same recipe page.

2nd Modified Recipe.php Controller
Code:
<?php
class Recipe extends MY_Controller{

function __construct() {
 parent::__construct();
  $uri = $this->uri->uri_string();
  $this->session->set_flashdata('uri', $uri);
}

function index(){
 $recipe_linkname = $this->uri->rsegment(3);
 if(!$recipe_linkname){
  $recipe_linkname = $this->recipe_model->first_linkname();
 }
 $recipe = $this->recipe_model->read_record($recipe_linkname);
 if(count($recipe) == 0){
  show_404('');
  die();
 }
 $data = array(
    'title' => "Shirley's Recipes : ".$recipe['name'],
  'columns' => array('toc', 'recipe'),
   'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}

function flipbook(){
 $this->require_login();
 $this->load->library('pagination');
   
       $config['base_url'] = site_url('recipe/flipbook');
     $config['total_rows'] = $this->recipe_model->num_rows();
    $config['uri_segment'] = '3';
       $config['per_page'] = 1;
      $config['num_links'] = 1;
  $config['display_pages'] = FALSE;
  $config['full_tag_open'] = '<div id="pagination">';
 $config['full_tag_close'] = '</div>';
 
 $this->pagination->initialize($config);
 $recipe = $this->recipe_model->read_records($config['per_page'], $this->uri->segment(3))->row_array();
   $data = array(
     'title' => "Shirley's Recipes : ".$recipe['name'],
     'columns' => array('toc', 'recipe_flipbook'),
      'recipe' => $recipe
 );
 $this->load->view('includes/template', $data);
}
 
function search(){
if var_dump($this->input->post('submit'));exit;
  die('Hello');
   $search = $this->input->post('query');
  $results = $this->recipe_model->search($search);
     $data = array(
     'title' => "Shirley's Recipes : Search Results",
     'columns' => array('toc', 'recipe_search'),
     'recipes' => $results,
  );
  $this->load->view('includes/template', $data);
  }
  else{
   redirect('recipe');
  }
}

function add(){
 $this->require_login();
 if($this->input->post('submit')){
  $data = array(
       'name' => $this->input->post('name'),
 'buttontext' => $this->input->post('buttontext'),
           'linkname' => $this->input->post('linkname'),
                'img' => $this->input->post('img'),
               'time' => $this->input->post('time'),
   'category' => $this->input->post('category'),
        'subcategory' => $this->input->post('subcategory'),
' ingredients' => $this->input->post('ingredients'),
  'equipment' => $this->input->post('equipment'),
'preparation' => $this->input->post('preparation'),
 'directions' => $this->input->post('directions')
  );
  $recipeid = $this->recipe_model->create_record($data);
  redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $data = array(
     'title' => "Shirley's Recipes : Add New Recipe",
   'columns' => array('toc', 'admin/recipe_edit'),
    'recipe' => array('name' => '',
                      'buttontext' => '',
                        'category' => '',
                     'subcategory' => '',
                        'linkname' => '',
                             'img' => '',
                            'time' => '',
                     'ingredients' => '',
                       'equipment' => '',
                     'preparation' => '',
                      'directions' => '')
  );
  $this->load->view('includes/template', $data);
 }
}

function edit(){
 $this->require_login();
 $id = $this->uri->segment(3);
 if($this->input->post('submit')){
  $data = array(
          'name' => $this->input->post('name'),
  'buttontext' => $this->input->post('buttontext'),
    'linkname' => $this->input->post('linkname'),
           'img' => $this->input->post('img'),
           'time' => $this->input->post('time'),
      'category' => $this->input->post('category'),
   'subcategory' => $this->input->post('subcategory'),
   'ingredients' => $this->input->post('ingredients'),
     'equipment' => $this->input->post('equipment'),
   'preparation' => $this->input->post('preparation'),
    'directions' => $this->input->post('directions')
   );
   $this->recipe_model->update_record($id, $data);
   redirect('recipe/'.$this->input->post('linkname'));
 }
 else{
  $recipe = $this->recipe_model->read_record($id);
  $data = array(
   'title' => "Shirley's Recipes : Edit Recipe : ".$recipe['name'],
   'columns' => array('toc', 'admin/recipe_edit'),
        'id' => $id,
  'recipe' => $recipe
  );
  $this->load->view('includes/template', $data);
 }
}

function delete(){
 $this->require_login();
 $this->recipe_model->delete_record($this->uri->segment(3));
 redirect('/');
}
}
// End - recipe.php
?>

I got the following error after the above code:
Code:
An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected 'var_dump' (T_STRING), expecting '('

Filename: /home/www/shirleysrecipes.100webspace.net/application/controllers/Recipe.php

Line Number: 52

Backtrace:

File: /home/www/shirleysrecipes.100webspace.net/index.php
Line: 315
Function: require_once
Line 54 is the var dump line?

Weird.

Thank you again!
Reply


Messages In This Thread
RE: Search Criteria Ignored, Only Redirects to Else Statement - by Josh1985 - 06-12-2019, 02:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB