• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search Criteria Ignored, Only Redirects to Else Statement

#1
Hello all!

I am experiencing a weird issue with a site now. Up until my web host updated PHP to 7.3.6, I had no issues with my search feature. I have read through the changelogs on php.net all with no help pointing me in the direction of what is now broken.

Code Modules In Use:
Code:
PHP 7.3.6
CodeIgniter 3.1.9

My_Controller.php:
Code:
<?php

class MY_Controller extends CI_Controller{
function __construct() {
 parent::__construct();
 $this->load->vars(array('toc' => $this->recipe_model->read_names_categories(),
 'admin_menu_items' => array(),
 'admin' => $this->is_logged_in()));
 if($this->is_logged_in()){
  date_default_timezone_set($this->session->userdata('tz'));
 }
 else{
  date_default_timezone_set('America/New_York');
 }
}
   
function is_logged_in(){
 $logged_in = $this->session->userdata('logged_in');
  if(isset($logged_in) && $logged_in){
   return true;
  }
  else{
   return false;
  }
 }
   
function require_login(){
 if(!$this->is_logged_in()){
  redirect('login');
 }
}
   
function format_date($datestr) {
 //date_default_timezone_set('UTC');
  $date = strtotime($datestr.' UTC');
 //date_default_timezone_set('America/New_York');
  $datestr = date("n/j/Y @ g:i A T", $date);
   return $datestr;
}  
}  
//End MY_Controller.php

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
?>

Recipe_model
Code:
<?php
class Recipe_model extends CI_Model {

function create_record($data){
 if(isset($data['buttontext']) and $data['buttontext'] == ''){
  $data['buttontext'] = NULL;
 }
 $this->db->insert('recipe', $data);
 return $this->db->insert_id();
}
 
function read_records($limit, $offset){
 $this->db->order_by('name', 'asc');
 if(isset($limit) && isset($offset)){
  $this->db->limit($limit, $offset);
 }
 $q = $this->db->get('recipe');
 return $q;
}
 
function read_record($key){
 if(is_numeric($key)){
  $this->db->where('id', $key);
 }
 else{
  $this->db->where('linkname', $key);
 }
 $q = $this->db->get('recipe');
 return $q->row_array();
}
 
function first_linkname(){
 $this->db->select('linkname, name');
 $this->db->order_by('name', 'asc');
 $this->db->limit(1);
 $q = $this->db->get('recipe');    
 return $q->row()->linkname;
}

function read_names(){
 $this->db->select('linkname, name');
 $this->db->order_by('name', 'asc');
 $q = $this->db->get('recipe');
 return $q->result();
}
 
function read_names_categories(){
 $this->db->select('buttontext, linkname, name, category, subcategory');
 $this->db->order_by('name', 'asc');
 $q = $this->db->get('recipe');
 return $q->result();  
}

function search($search){
 $terms = explode(" ", $search);
 $match = "";
 foreach($terms as $term){
  $match .=  $term;
 }
 $querystr = "SELECT *, MATCH(name, linkname, ingredients, equipment, preparation, directions, category, subcategory, keywords) AGAINST('".$match."') as score FROM recipe WHERE MATCH(name, linkname, ingredients, equipment, preparation, directions, category, subcategory, keywords) AGAINST('".$match."') ORDER BY score DESC;";
 $q = $this->db->query($querystr);
 return $q->result();
}

function update_record($id, $data){
 if(isset($data['buttontext']) and $data['buttontext'] == ''){
  $data['buttontext'] = NULL;
 }
 $this->db->where('id', $id);
 $this->db->update('recipe', $data);
}
 
function delete_record($id){
 $this->db->where('id', $id);
 $this->db->delete('recipe');
}
 
function num_rows(){
 return $this->db->get('recipe')->num_rows();
}
}
// End - recipe_model.php
?>

Recipe_search View (This should load whether or not results were found but it NEVER loads)
Code:
<div id="recipelist" class="content">
<h1>Recipe Search</h1>
 <div class="recipesearch">
  <ol>
   <?php if(!empty($recipes)): foreach($recipes as $recipe): ?>
    <li><a href="/recipe/<?=$recipe->id ?>"><?=$recipe->name ?></a><span class="confidence"><?=$recipe->score ?></span></li>
    <?php endforeach; ?>
  </ol>
 </div>
 <?php else: ?>
 <h3>No matching recipes</h3>
 <?php endif; ?>
</div>

I hope that is all the code you need to help me. If not, I will be happy to provide more.

A brief overview of the issue is if someone comes to the site to search for a recipe, no matter what they put in and submit; the search redirects them back to the first alphabetical recipe on the site. No matter what is entered.

What used to happen when a search was performed is the site would open up the "Recipe_search.php" View and show them that. Now, all I get is the first alphabetical recipe page. What am I missing here?

Thank you in advance!
Reply

#2
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!
Reply

#3
(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

#4
syntax error!

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

and post the result
Reply

#5
(06-13-2019, 01:35 AM)hc-innov Wrote: syntax error!

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

and post the result

Hmm, another Syntax Parse Error.....

Modified Function
Code:
function search(){
var_dump($this->input->post());
exit;
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');
  }
}

Error
Code:
An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected ';'

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

Line Number: 55

Backtrace:

File: /home/www/shirleysrecipes.100webspace.net/index.php
Line: 315
Function: require_once

Line 55: die('Hello');
Reply

#6
oops (forgotten parenthesis)

better:

PHP Code:
if ($this->input->post('submit')){
....
} else {
....

Reply

#7
(06-13-2019, 08:01 AM)hc-innov Wrote: oops (forgotten parenthesis)

better:

PHP Code:
if ($this->input->post('submit')){
....
} else {
....


Resulted Output
Code:
array(2) { ["query"]=> string(1) "m" ["submit"]=> string(0) "" }
Reply

#8
In that case change ALL your $this->input->post('submit') into $this->input->method() === 'post' instead.
You aren't sending any data inside your submit button, so it will always be null.

Not sending data:
<input type="submit" value="Submit!" />

Sending data:
<input type="submit" name="submit" value="Submit!" />

Or you can do $this->input->post() instead. Depending how you would like to validate that all your fields have been submitted.
Reply

#9
(06-13-2019, 09:56 AM)jreklund Wrote: In that case change ALL your $this->input->post('submit') into $this->input->method() === 'post' instead.
You aren't sending any data inside your submit button, so it will always be null.

Not sending data:
<input type="submit" value="Submit!" />

Sending data:
<input type="submit" name="submit" value="Submit!" />

Or you can do $this->input->post() instead. Depending how you would like to validate that all your fields have been submitted.

Hmm, if what you suggest is accurate then why is it that ALL my other form submits work just fine. Like sending data to the database, just not my search function?

Also, as far as "sending data"... I am not sure what you mean by that. I am not aware I was "sending" anything. The search is supposed to be a simple query of the database and return a view for the result. So what exactly am I supposed to be sending? If I am not mistaken the Else statement was originally written as more of a debugging protocool to alert to something not working correctly visually rather than as an error. Any thoughts there?

For example, I tried the following corrections:

Modified Function #1:
Code:
function search(){
if ($this->input->method() === 'post'
    $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');
   }
}

Result #1:
Code:
An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected '$search' (T_VARIABLE)

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

Line Number: 55

Backtrace:

File: /home/www/shirleysrecipes.100webspace.net/index.php
Line: 315
Function: require_once

Please make no mistake, if your suggestion is my fix for this issue I will happily implement it but I am confused as to why only 1 out of approximately 4 form submits has this issue?

Thank you again!
Reply

#10
You haven't provided us with any code for your view (where the search submit button are), so I can't tell you why it ain't working. If you would be so kind to post it and a form that's working.

If a type="submit" dosen't have a name="" field it will not show up. If you provided it with name="submit" it will populate $this->input->post('submit') with whatever your value="" are.

eg.
Code:
<input type="submit" name="submit" value="Submit!" />

Will give you: Submit!

Code:
<input type="submit" value="Submit!" />

Will give you: null (not a string, just null)

And therefor return false in an if statement. So I guess you don't have a name="" on that particular button, but everything else.

You need to close your your parenthesis.
Code:
if ($this->input->method() === 'post')
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.