Welcome Guest, Not a member yet? Register   Sign In
$this->validation->display_errors() displays same error twice
#1

[eluser]Computerzworld[/eluser]
I have used CI file uploading code and to check whether the file is valid or not I have displayed error by using $this->validation->display_errors(). But it displays same error twice. Here is the code which I have used.

Code:
if($this->upload->do_upload())
            {
                $this->mdl_trains->scheduleFile = $_FILES['userfile']['name'];
                $this->mdl_trains->scheduleId = $this->scheduleId;
                $this->mdl_trains->trainId = $this->trainId;
                $this->mdl_trains->saveSchedule();
                redirect("admin/trains/trainSchedule/trainId/{$this->trainId}");
            }
            elseif($_FILES['userfile']['name']!="" && !$this->upload->do_upload())
            {
                $this->validation->error_string = $this->upload->display_errors();
            }

I have assigned the error to $this->validation->error_string. But it displays error twice. How can I solve it? Plz help me. Thanks in advance.
#2

[eluser]xwero[/eluser]
In the if you do an upload and in the elseif you do and upload that's why you are getting two errors. A better way to check if the upload is valid is
Code:
// check if the upload file is selected
if($_FILES['userfile']['error'] != 4)
{
   if($this->upload->do_upload())
   {
                $this->mdl_trains->scheduleFile = $_FILES['userfile']['name'];
                $this->mdl_trains->scheduleId = $this->scheduleId;
                $this->mdl_trains->trainId = $this->trainId;
                $this->mdl_trains->saveSchedule();
                redirect("admin/trains/trainSchedule/trainId/{$this->trainId}");
    }
    else
    {
        // .= adds the upload error string to the validation error string
        // $this->validation->error_string = $this->upload->display_errors(); overwrites the validation error string
        $this->validation->error_string .= $this->upload->display_errors();
    }
}
else
{
   // if file required you can build error string here
}
#3

[eluser]Computerzworld[/eluser]
thanks a lot.... it worked Smile




Theme © iAndrew 2016 - Forum software by © MyBB