Welcome Guest, Not a member yet? Register   Sign In
Page Refresh poblem
#1

[eluser]Swayam[/eluser]
Hello Guys..

I am new to codeigniter and practicing basic tasks like login,registration,editing profile and all..i have an issue that when a user edit profile and redirect to home page ,m displaying his information on home page and when user refresh the home page (not by F5 but through cursor points on address bar and press enter) all the field get blank and all the fields in database gets 0.. i m storing it in session at the time when user logged in & editing, on home page retrieving data through session ..is this a problem with session or anything other !!plz help me..


Thanks in advance
#2

[eluser]boltsabre[/eluser]
Post some code please inside the code tags.

My guess is that you are "redirecting" to the homepage by using "this->load->view" instead of actually using "redirect()"...???
#3

[eluser]Swayam[/eluser]
Code:
function edit_details()
{

   $e_uname = $this->input->post('e_uname');
   $e_fname = $this->input->post('e_fname');
  $e_emailid = $this->input->post('e_emailid');
   $e_address = $this->input->post('e_address');
   $e_city = $this->input->post('e_city');
   $e_contact = $this->input->post('e_contact');
  $data = array('uname'=>$e_uname,'fname'=>$e_fname,'emailid'=>$e_emailid,'address'=>$e_address,'city'=>$e_city,'contact'=>$e_contact);
   $sid = $this->session->userdata('id');
  $this->load->model('dbmodel');
  $this->dbmodel->update_entry($data,$sid);
  //echo "Your profile is updated successfully";
  $this->load->view('home');

}
this is my controller function..this function is called on the form action of edit page..
#4

[eluser]Swayam[/eluser]
i have got it..in the place of $this->load->view('home') i have use redirect('url') and it works..


Thanks You Sir..thnk u very much..
#5

[eluser]boltsabre[/eluser]
Yeah, using "this->load->view" only loads on new view on top of your controller (for want of a better expression)...

Your controller has these lines of code:
Code:
$e_uname = $this->input->post('e_uname');
   $e_fname = $this->input->post('e_fname');...

When the user has been redirected to the home page via "this->load->view" and then does a refresh, there is no form, no $_POST, so
Code:
$e_uname = $this->input->post('e_uname');
print_r($e_uname); // will print 0 or false or null or something)
because $this->input->post('e_uname'); does not exist.

The rest of your code was also running after the refresh
$this->load->model('dbmodel');
$this->dbmodel->update_entry($data,$sid);

And inserting a big bunch of...NOTHING into your DB!!!

After successful form submission ALWAYS use redirect to get to a new "clean" controller/view
#6

[eluser]boltsabre[/eluser]
On a side note, this is a good example of why you should be validating your input!!!

I'm sure that at least one of your inputs MUST be entered by the user? Otherwise what is the point of even having the form???

As your current code stands a user can come to this page, click submit, insert a blank row of data into your table (ouch) and be successfully redirected.

Also...

If you just name your inputs the same as your table column names you can just do this, instead of all that "assigning inputs to variables, and then inserting those variables into an array and then finally passing the array to your model call" (LOTS AND LOTS of unneeded code that is just waiting to create bugs and unneeded variables sucking up server resources and processing time).
Code:
$this->load->model('dbmodel');
$this->dbmodel->update_entry($this->input->post(), $this->session->userdata('id'));

If you do need to get your post variables into an array for whatever reason, there is no need to assign them to a variable first, you can do it like this:
Code:
$data = array('uname'=>$this->input->post('e_uname'),...
#7

[eluser]Swayam[/eluser]
Code:
$data = array('uname'=>$this->input->post('e_uname'),...
ok..this is also a good way..direct assigning..removing unnecessary variables..i will follow it next time..yes..definitely i m taking inputs from the user..i also have to put validation in it..
Sir,i need your help once again..i have a logout link..which is working fine..here is the code..
Code:
public function logout()
{
  $this->session->sess_destroy();
  redirect('http://localhost/CodeIgniter_2.1.2/index.php/login/flogout','refresh');
}
function flogout()
{

$this->load->view('login_page','refresh');
}
but there is one problem ..when user comes to login page after logout and again pressing back button..then it shows the previous page..which should not be happen..Glad if u help your student..!!




Theme © iAndrew 2016 - Forum software by © MyBB