doubengshao8872 2017-10-05 05:51
浏览 50
已采纳

插入表单值时提交按钮不起作用

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

  • 写回答

3条回答 默认 最新

  • dqroc48068 2017-10-05 06:00
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?