[英]Insert form data in database
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. 我认为问题escape_str
在模型中的escape_str
上。 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;
}
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>";
Change to 改成
foreach($ciList as $row){
echo "<p><input type='checkbox' name='cname[]' value='".$row->affected_ci."'/>".$row->affected_ci."</p>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.