Welcome Guest, Not a member yet? Register   Sign In
Best way for checking true result
#11

[eluser]InsiteFX[/eluser]
That is good, the reason for xss_cleaning the input
Never Never Never trust user input!
#12

[eluser]cartalot[/eluser]
keep it simple - check for the condition success or fail, then move to appropriate method
Code:
// set it to false
$this->session->set_flashdata("insertsuccess", FALSE);

if ($this->model_name->my_insert($data) == TRUE)
{
// set to true
    $this->session->set_flashdata("insertsuccess", TRUE);
// go to another method
$this->takenextstep();
}
else
{
$this->noresults();
}
#13

[eluser]someone Smile[/eluser]
Right now I was trying my script if all works like it should, but I found a error.
Model:
Code:
public function updatedata($table, $nameid, $idnum, $data)
{
if ($this->db->where($nameid, $idnum)->update($table, $data))
{
  return $this->db->affected_rows();
}
}

If I change input data it works good, but if I leave as before - without changing, I get error, because there is not affected rows. What's the best replacement for this?

It will be this good?
Code:
public function updatedata($table, $nameid, $idnum, $data)
{
if ($this->db->where($nameid, $idnum)->update($table, $data))
{
  return TRUE;
}
}
#14

[eluser]CroNiX[/eluser]
Yeah, affected_rows() will only work if an update actually took place, which it doesn't unless the data actually changes in some way. Standard MySQL behavior.

I prefer returning TRUE on success and FALSE otherwise. You are only returning true if there isn't an error and returning nothing if there is one.
Code:
public function updatedata($table, $nameid, $idnum, $data)
{
return $this->db->where($nameid, $idnum)->update($table, $data);
}
//returns TRUE if there isn't an error and FALSE if there is one




Theme © iAndrew 2016 - Forum software by © MyBB