我想允许人们通过将其输入到一个字段来提交他们的联系人,它最终会将其发送到数据库,但已经尝试了很长一段时间并且无法找出它有什么问题,如果可能的话,请让我知道如何返回当它在数据库中时,一个回声说“SENT”。如果可能的话,重定向到同一页面,甚至不需要刷新即可将该 SENT 显示给人们。
这是我的控制器
$this->config->db_config_fetch();
$this->load->model('skills_model');
//Get Form Data
$this->input->post('submitsms') ;
//GEt phone number from field
$type = $this->input->post('phonenumber');
//Call model
$this->skills_model->addsms($type);
}
这是我的观点@主页
<form method="post" action="<?php echo site_url(''); ?>" name="form" enctype="multipart/form-data">
<label>SMS Subscription</label>
<input type="text" name="phonenumber" placeholder="Phone Number here">
<button class="btn btn-info" name="submitsms" type="submit">Subscribe</button>
</form>
这是我的模特
function addsms($type){
$this->db->set('number', $type);
$this->db->insert('subscribers');
}
我还尝试了以下
function addsms($type){
$sql = "INSERT INTO 'subscribers' ('number') VALUES ($type)";
$this->db->query($sql);
echo $this->db->affected_rows();
}
你的建议会有很大帮助!谢谢你!