I want to allow people to submit their contacts by entering it into a field and it would eventually send it to the database but been trying it for quite some time and cant find out whats wrong with it, if possible do let me know how to return a echo saying "SENT" when its in database. Redirecting to the same page, if possible , dont even need a refresh to get that SENT shown to people.
This is my Controller
$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);
}
This is my View @ home page
<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>
This is my Model
function addsms($type){
$this->db->set('number', $type);
$this->db->insert('subscribers');
}
I also tried the following
function addsms($type){
$sql = "INSERT INTO 'subscribers' ('number') VALUES ($type)";
$this->db->query($sql);
echo $this->db->affected_rows();
}
You advice would be of a great help! thank you!
A small example ...........
View file
<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>
Controller...........
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";
}
Model................
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();
}
I hope this example will help you .........if you have any doubts ask