2012-10-19 81 views
0

我想让人们通过将其输入到一个字段中来提交他们的联系人,它最终会将其发送到数据库,但它已经尝试了很长时间,并且无法找出什么如果可能,请让我知道如何在数据库中返回说“SENT”的回声。如果可能的话,重定向到同一页面,甚至不需要刷新就可以让人们看到SENT。无法将数据插入到数据库(PHP MVC)

这是我的控制器

$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(); 
} 

你的建议将是一个很大的帮助!谢谢!

回答

2

一个小例子...........

查看文件

<form action="<?php echo ROOT_FOLDER ?>/add_price" method="post"> 

<input type="text" class="text" name="amount" value="<?php echo set_value('amount'); ?>" /> 

<input type="submit" class="submit" value="Approve" /> 
</form> 

控制器...........

public function post_add_price() 
{ 
    $data = array(
'amount'=>$this->input->post('amount'), 
); 
$this->model->add_amount($data); //sending amount to model to insert in dataabse 
echo "Amount added to database"; 
} 

型号................

public function add_amount($data) 
{ 
    $this->insert_helper('order_amount_table',$data); 
} 

public function insert_helper($table_name, $data_array){ 
    $this->db->insert($table_name,$data_array); 
    return $this->db->insert_id(); 

} 

我希望这个例子能帮助你....... ..如果您有任何疑问请问

+0

这是在我的web应用程序中使用的一个正在开发的工作示例............. –

+0

嗨Venkat,如果我想重定向对自己? action =“<?php echo ROOT_FOLDER?>/add_price”似乎像在其他地方重定向一样,如果我删除了add_price,它会不会马上消失? – CodeGuru

+0

哎抱歉,不是add_price它是post_add_price ......这是必须的,因为当用户提交的数量我们正在调用控制器功能.......如果你想重定向只是加载一个视图文件后插入价格在数据库和通过数量数组来查看文件......... –

相关问题