Question

I have a problem: Every time I insert something in the database, at the end of it a / appears. How can I remove this? I think the problem is with escape_str in the model. What can I replace it with?

VIEW

foreach($ciList as $row)
{
  echo "<p><input type=checkbox name=cname[]  value=".$row->affected_ci."/>".$row->affected_ci."</p>";
}

CONTROLLER

public function insert()
{
    $this->load->model('some_model');
    $name = $this->input->post('name');
    $cname = $this->input->post('cname');

    foreach($cname as $key=>$value)
    {
      $success = $this->some_model->insertPerson($name,$cname[$key]);
    }

    if($success == TRUE)
      $this->insert_page(TRUE);
    else 
      $this->insert_page(FALSE);
}

MODEL

public function insertPerson($name,$cname)
{
    $escName = $this->db->escape_str($name);
    $eciName = $this->db->escape_str($cname);
    $queryStr = "INSERT INTO appwarehouse.ci_table(app_id,ci_name) VALUES ('$escName','$eciName')";
    $query = $this->db->query($queryStr);
    return $query;
}
Was it helpful?

Solution

Change

echo "<p><input type=checkbox name=cname[]  value=".$row->affected_ci."/>".$row->affected_ci."</p>";

to

echo "<p><input type=checkbox name=cname[]  value='".$row->affected_ci."' />".$row->affected_ci."</p>";

OTHER TIPS

Change to

foreach($ciList as $row){
            echo "<p><input type='checkbox' name='cname[]'  value='".$row->affected_ci."'/>".$row->affected_ci."</p>";
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top