Welcome Guest, Not a member yet? Register   Sign In
cannot user redirect() function..
#13

[eluser]scorpioniz[/eluser]
[quote author="Tim Brownlaw" date="1410660500"]Well scorpioniz insists that the insert and updates are working indicating that execution is falling into the else block... Which I find a little hard to believe with the provided code sample as $data doesn't exist locally in the function and I cannot see where it's being defined.

So it's obvious that IF the else block is being executed somethings going BANG halting execution... Or the redirect would be getting executed... We're flying blind here!

So A Quick check would be to do this...
Code:
<?php if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

class Someclass extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public function edit($id = NULL)
  {
    $user_id = 25;
    $event = $this->database->GetSingle('events', array('id' => $id, 'userid' => $user_id));
    $this->data['event'] = $event;
    //redirect('user/event/show/'.$event['id']);
    if($this->form_validation->run('event/createedit') == FALSE)
    {
      $this->ajaxValidation('event/createedit');
    }
    else
    {
      $event_id = 1; // Set this to something valid for testing
      redirect('user/event/show/'.$event_id); // NOW Does this work when the Form is Valid???
    }
  }
}
[/quote]

sorry.. that i didn't put all my code.. :? i thought it will be easier to read.. but still nothing helping..
event if in else it is
Code:
$event_id = 1;
redirect('user/evet/show/'.$event_id);

it starts to load show page but later it still opens edit page..

so here is my all code of that function.. Smile

Code:
function edit($id = NULL, $test = null){
  if($id){
   $this -> data['page_title'] = 'Edit event';
  }else{
   $this -> data['page_title'] = 'Add event';
  }
  $this->data['includes'] = array('wizard', 'element', 'wysihtml5', 'form');

  $event = $this->database->GetSingle('events', array('id' => $id, 'userid' => $this->utilities->GetUserID()));
  $this->data['event'] = $event;
  
  if($this->form_validation->run('event/createedit') == FALSE){
   $this->ajaxValidation('event/createedit');
  }else{
  
   $img = $this->utilities->UploadEventImage('logo_img');
   $img2 = $this->utilities->UploadEventImage('portfolio_img');
  
   if($event != NULL && $event['logo_img'] != NULL && $img != ''){
    if( file_exists($event['logo_img']))
     unlink($event['logo_img']);
   }
   if($event != NULL && $event['portfolio_img'] != NULL && $img2 != ''){
    if( file_exists($event['portfolio_img']))
     unlink($event['portfolio_img']);
   }
  
   $privacy =($this->input->post('privacy') == 1) ? 1 : 0;
   $allowpublicregistration =($this->input->post('allowpublicregistration') == 1) ? 1 : 0;
  
   if($this -> input-> post('unlimited-people')){
    $max_quantity = 0;
   }else{
    $max_quantity = $this->input->post('max_quantity');
   }
  
   $data = array(
    'userid'  => $this->utilities->GetUserID(),
    'title'   => $this->input->post('title'),
    'description' => $this->input->post('description'),
    'startdate'  => $this->input->post('startdate') .' '. $this->input->post('starttime'),
    'enddate'   => $this->input->post('enddate') .' '. $this->input->post('endtime'),
    'location'  => $this->input->post('location'),
    'address'  => $this->input->post('address'),
    'webaddress' => $this->input->post('webaddress'),
    'privacy'  => $privacy,
    'allowpublicregistration' => $allowpublicregistration,
    'max_quantity' => $max_quantity,
    'about' => $this -> input -> post('about')
   );
  
   if($data['startdate'] > $data['enddate']){
    $error_message = 'The First Submission Date must be greater than the Last Submission Date.';
    return $this->form_validation->set_message($error_message);
   }
  
   if($img != ''){
    $data['logo_img'] = $img;
   }
   if($img2 != ''){
    $data['portfolio_img'] = $img2;
   }
  
   if($event == NULL){
    $this->database->Insert('events', $data);
    $event_id = $this -> database -> GetLastID();
    
    $default_template = $this->database->GetSingle('events_templates', array('default' => 1));
    $this -> database -> Insert('events_users_templates', array('event_id' => $event_id, 'template_id' => $default_template['id']));
   }else{
    $this->database->Update('events', $data, array('id' => $event['id']));
    $event_id = $event['id'];
   }
   var_dump($this->db->last_query());
   var_dump($event_id);
   exit;
  
   if($event_id != 0){
    redirect('user/event/show/'.$event_id);
   }
   exit;
  }
}

and i have made screenshots of my sql, and developer tools network tab with some comments in it, i hope it will help something.. :/

Screenshot


Messages In This Thread
cannot user redirect() function.. - by El Forum - 09-12-2014, 07:26 AM
cannot user redirect() function.. - by El Forum - 09-12-2014, 09:12 PM
cannot user redirect() function.. - by El Forum - 09-13-2014, 07:15 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 08:28 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 09:00 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 09:20 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 09:28 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 09:36 AM
cannot user redirect() function.. - by El Forum - 09-13-2014, 04:17 PM
cannot user redirect() function.. - by El Forum - 09-13-2014, 04:19 PM
cannot user redirect() function.. - by El Forum - 09-13-2014, 04:51 PM
cannot user redirect() function.. - by El Forum - 09-13-2014, 07:08 PM
cannot user redirect() function.. - by El Forum - 09-15-2014, 12:22 AM
cannot user redirect() function.. - by El Forum - 09-15-2014, 01:12 AM
cannot user redirect() function.. - by El Forum - 09-15-2014, 05:39 PM
cannot user redirect() function.. - by El Forum - 09-15-2014, 06:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB