I've been having some really crazy problems with my session userdata. It seems like it just stops showing up in my views page after making some edits, and I cannot figure out why. I am using notepadd++ to do my editing of the php files, so I just "undo" the edits, but then it still will not work. It makes no sense. I'm a novice so I will do my best to explain.
Website visitor fills out a form. The form is validated with the following function in the controller:
PHP Code:
function _mainsearchvalidate($searchtype)
{
$this->form_validation->set_rules('fname', 'First Name', 'required|trim|xss_clean');
$this->form_validation->set_rules('lname', 'Last Name', 'required|trim|xss_clean');
$this->form_validation->set_rules('age', 'Age', 'trim|xss_clean');
$this->form_validation->set_rules('city', 'City', '');
$this->form_validation->set_rules('state', 'State', 'required');
if($this->form_validation->run() == FALSE){
$data['search_type'] = $searchtype;
$this->themes->view('searches/home', $data);
} else {
$data['search_type'] = $searchtype;
$tempfname = $this->input->post('fname');
$templname = $this->input->post('lname');
$currentstate = $this->input->post('state');
$originalage = $this->input->post('age');
if (!empty($originalage)){
$numberofrows = rand(4, 7);
} else {
$numberofrows = rand(9, 25);
}
if (!empty($originalage) && ($originalage < 18)) {
$originalage = rand(18, 21);
}
elseif (!empty($originalage) && ($originalage > 102)) {
$originalage = rand(81, 101);
}
elseif (empty($originalage)) {
$mainpersonage = rand(18,78);
}
if (empty($mainpersonage)) {
$mainpersonage = $originalage;
}
$resultsarray[0] = $numberofrows;
$resultsarray[1] = $this->input->post('fname');
$resultsarray[2] = $this->input->post('lname');
$resultsarray[3] = $mainpersonage;
$resultsarray[4] = $this->input->post('state');
$resultsarray[5] = $this->_statephone($this->input->post('state'));
$resultsarray[6] = $this->input->post('fname');
$resultsarray[7] = $this->input->post('lname');
$resultsarray[8] = $this->_agegenerator($originalage);
$resultsarray[9] = $this->_statephone($this->input->post('state'));
$resultsarray[10] = $this->_createnames($tempfname, $templname);
$resultsarray[11] = $this->_agegenerator($originalage);
$resultsarray[12] = $this->_statephone($this->input->post('state'));
$resultsarray[13] = $this->_createnames($tempfname, $templname);
$resultsarray[14] = $this->_agegenerator($originalage);
$resultsarray[15] = $this->_statephone($this->input->post('state'));
$resultsarray[16] = $this->_createnames($tempfname, $templname);
$resultsarray[17] = $this->_agegenerator($originalage);
$resultsarray[18] = $this->_statephone($this->input->post('state'));
$resultsarray[19] = $this->_createnames($tempfname, $templname);
$resultsarray[20] = $this->_agegenerator($originalage);
$resultsarray[21] = $this->_statephone($this->input->post('state'));
$resultsarray[22] = $this->_createnames($tempfname, $templname);
$resultsarray[23] = $this->_agegenerator($originalage);
$resultsarray[24] = $this->_statephone($this->input->post('state'));
$resultsarray[25] = $this->_createnames($tempfname, $templname);
$resultsarray[26] = $this->_agegenerator($originalage);
$resultsarray[27] = $this->_statephone($this->input->post('state'));
$resultsarray[28] = $this->_createnames($tempfname, $templname);
$resultsarray[29] = $this->_agegenerator($originalage);
$resultsarray[30] = $this->_statephone($this->input->post('state'));
$resultsarray[31] = $this->_createnames($tempfname, $templname);
$resultsarray[32] = $this->_agegenerator($originalage);
$resultsarray[33] = $this->_statephone($this->input->post('state'));
$resultsarray[34] = $this->_createnames($tempfname, $templname);
$resultsarray[35] = $this->_agegenerator($originalage);
$resultsarray[36] = $this->_statephone($this->input->post('state'));
$resultsarray[37] = $this->_createnames($tempfname, $templname);
$resultsarray[38] = $this->_agegenerator($originalage);
$resultsarray[39] = $this->_statephone($this->input->post('state'));
$resultsarray[40] = $this->_createnames($tempfname, $templname);
$resultsarray[41] = $this->_agegenerator($originalage);
$resultsarray[42] = $this->_statephone($this->input->post('state'));
$resultsarray[43] = $this->_createnames($tempfname, $templname);
$resultsarray[44] = $this->_agegenerator($originalage);
$resultsarray[45] = $this->_statephone($this->input->post('state'));
$resultsarray[46] = $this->_createnames($tempfname, $templname);
$resultsarray[47] = $this->_agegenerator($originalage);
$resultsarray[48] = $this->_statephone($this->input->post('state'));
$resultsarray[49] = $this->_createnames($tempfname, $templname);
$resultsarray[50] = $this->_agegenerator($originalage);
$resultsarray[51] = $this->_statephone($this->input->post('state'));
$resultsarray[52] = $this->_createnames($tempfname, $templname);
$resultsarray[53] = $this->_agegenerator($originalage);
$resultsarray[54] = $this->_statephone($this->input->post('state'));
$resultsarray[55] = $this->_createnames($tempfname, $templname);
$resultsarray[56] = $this->_agegenerator($originalage);
$resultsarray[57] = $this->_statephone($this->input->post('state'));
$resultsarray[58] = $this->_createnames($tempfname, $templname);
$resultsarray[59] = $this->_agegenerator($originalage);
$resultsarray[60] = $this->_statephone($this->input->post('state'));
$resultsarray[61] = $this->_createnames($tempfname, $templname);
$resultsarray[62] = $this->_agegenerator($originalage);
$resultsarray[63] = $this->_statephone($this->input->post('state'));
$resultsarray[64] = $this->_createnames($tempfname, $templname);
$resultsarray[65] = $this->_agegenerator($originalage);
$resultsarray[66] = $this->_statephone($this->input->post('state'));
$resultsarray[67] = $this->_createnames($tempfname, $templname);
$resultsarray[68] = $this->_agegenerator($originalage);
$resultsarray[69] = $this->_statephone($this->input->post('state'));
$resultsarray[70] = $this->_createnames($tempfname, $templname);
$resultsarray[71] = $this->_agegenerator($originalage);
$resultsarray[72] = $this->_statephone($this->input->post('state'));
$resultsarray[73] = $this->_createnames($tempfname, $templname);
$resultsarray[74] = $this->_agegenerator($originalage);
$resultsarray[75] = $this->_statephone($this->input->post('state'));
$resultsarray[76] = $this->_createnames($tempfname, $templname);
$resultsarray[77] = $this->_agegenerator($originalage);
$resultsarray[78] = $this->_statephone($this->input->post('state'));
$resultsarray[79] = $this->_createnames($tempfname, $templname);
$resultsarray[80] = $this->_agegenerator($originalage);
$resultsarray[81] = $this->_statephone($this->input->post('state'));
$resultsarray[82] = $this->recordschecklistgen();
$resultsarray[83] = $this->recordschecklistgen();
$resultsarray[84] = $this->recordschecklistgen();
$resultsarray[85] = $this->recordschecklistgen();
$resultsarray[86] = $this->recordschecklistgen();
$resultsarray[87] = $this->recordschecklistgen();
$resultsarray[88] = $this->recordschecklistgen();
$resultsarray[89] = $this->recordschecklistgen();
$resultsarray[90] = $this->recordschecklistgen();
$resultsarray[91] = $this->recordschecklistgen();
$resultsarray[92] = $this->recordschecklistgen();
$resultsarray[93] = $this->recordschecklistgen();
$resultsarray[94] = $this->recordschecklistgen();
$resultsarray[95] = $this->recordschecklistgen();
$resultsarray[96] = $this->recordschecklistgen();
$resultsarray[97] = $this->recordschecklistgen();
$resultsarray[98] = $this->recordschecklistgen();
$resultsarray[99] = $this->recordschecklistgen();
$resultsarray[100] = $this->recordschecklistgen();
$resultsarray[101] = $this->recordschecklistgen();
$this->session->set_flashdata('type', $searchtype);
$this->session->set_userdata($resultsarray);
redirect('/search/results', 'refresh');
}
}
In my views page, I am retrieving the userdata with this:
PHP Code:
<?= ucwords($this->session->userdata[1]); ?>
This WAS working until I made some edits. I undid the edits and it's still not working. My views page is giving me this error for each reference to the userdata:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: searches/completed.php
Line Number: 11
I have been having some problems with this over the weekend while working on this page but I have always been able to "fix" it. Usually undoing edits will fix the problem, but one time when this happened undoing the edits didn't work. I fixed it by just switching these two lines of code around from the controller (near the bottom of what I posted for the controller's validate function code):
PHP Code:
$this->session->set_flashdata('type', $searchtype);
$this->session->set_userdata($resultsarray);
That doesn't make sense to me that switching those two lines of code suddenly fixed the undefined offset error, but it did. Naturally, that's the first thing I tried when this happened this time, but that did not work for me. I have run the code form the controller and the view page through a php syntax error error checker and both pages were clean. So I am out of ideas.
Also I would like to add some information regarding the setup of the views page. Right now I am testing this new functionality I am designing, which is based off existing functionality on the site, just another branch of it with more features, by using an if statement. Basically,
PHP Code:
<?php if($search_type == 'thesearchtype'): ?>
new functionailty here
old functionality here
I am doing this so I can test what I am designing while the visitors of the site can still use the old functionality.
Anytime the old functionality code is being used, I can refresh the search results page (the view page) and all of the information generated for the table stays the same. This is what I want. When search results are returned, those results should display any time a user refreshes the page. However, this does not happen with my new functionality. Instead, the search results on the views page return the results from the PREVIOUS search. Then when I refresh the page, the results from the intended search are displayed. So whenever the view page is displayed showing my search results from the new functionality, I must refresh the page again to display the actual search results. That is, if that damn undefined index error isn't getting in the way. Assuming I can get rid of the undefined index error and get my data to display on the views page, I will also need to address this problem where I need to refresh the page to see the actual results. I am not sure if there is a relation between these problems so I figured I would mention this.