0

controller: Purchase.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Purchase extends CI_Controller 
{
    function __construct()
    {
        parent:: __construct();
        $this->load->model('purchase_data');
    }
    public function add_product_master()
    {
        if($this->input->post('submit'))
        {
            $data = array(
                        'product_name'=> $this->input->post('product_name'),
                        'category'=> $this->input->post('category'),
                        'sub_category'=> $this->input->post('sub_category'),
                        'description'=> $this->input->post('description'),
                        );
            $query = $this->db->insert('product_master',$data); 
            if($query == true)
            {
                $this->session->set_flashdata('message', '<p style="color: green;font-weight: bold;">Your product added successfully.</p>');
                echo "<meta http-equiv='refresh' content='1'>";
            }
            else
            {
                $this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Error!</p>');
            }
        }
        $this->load->view('product-master');
    }
}

view: product-master.php

<?php echo $this->session->flashdata('message');?>
<form class="form-horizontal form-label-left" method="post">
  <input type="text" name="product_name" id="product_name" required="required" />
  <input type="text" name="category" id="category" required="required" />
  <input type="text" name="sub_category" id="sub_category" required="required" />
  <textarea name="description" id="description" required="required"></textarea>
  <input type="submit" name="submit" id="submit" class="btn btn-success" value="submit">
</form>

I have created a form having name product-master.php. But when I click on submit button it does't inserting form value or does't showing any flashdata message don't know why. So, How can I fix this problem ? Please help me.

Thank You

4
  • 1
    you need to add action to form tag. <form role="form" method="post" action="<?php echo site_url('purchase/add_product_master');?>"> Commented Oct 5, 2017 at 5:59
  • are you receiving any error or something? Commented Oct 5, 2017 at 6:00
  • add action method in form tag @omkara Commented Oct 5, 2017 at 6:00
  • no I am not receiving any error @NaimMalek Commented Oct 5, 2017 at 6:03

3 Answers 3

1

Problem in this line. you need to add action when form is submit

 <form class="form-horizontal form-label-left" method="post"
 action="<?php echo site_url('purchase/add_product_master');?>">

use this code in this function add_product_master at the start of this function

echo "<pre>";
print_r($this->input->post());
exit;
Sign up to request clarification or add additional context in comments.

4 Comments

replace above line with your code and clear browser cache then submit form
what happen when you click on submit button?
when click on submit button it show nothing like flashdata or not inserting form value
@omkara i have update my answer try this and show result
0

you need to add action method to form tag.

<form role="form" method="post" action="<?php echo site_url('purchase/add_product_master');?>"> 

3 Comments

have you add action method? submit button are work when action method is applied
submit button are work when action method is applied is wrong statement. If request to be sent on same url/page then action is not required.
@B.Desai thanks for correction. try changing if($this->input->post('submit')) to if (!empty($_POST))
0

the action attribute is missing in your form, So you should add action attribute while adding form to your document.

<form class="form-horizontal form-label-left" method="post" action="URL">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.