Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中将值从查看页面传递到控制器页面_Php_Database_Html_Forms_Codeigniter - Fatal编程技术网

Php 在codeigniter中将值从查看页面传递到控制器页面

Php 在codeigniter中将值从查看页面传递到控制器页面,php,database,html,forms,codeigniter,Php,Database,Html,Forms,Codeigniter,我试图通过php CodeIgniter将数据插入数据库,并在提交按钮期间在同一页面中显示结果。下面是我的代码。问题是我没有从查看页面获取任何值,我检查了打印结果,结果是一个空数组。请帮忙。查看页面 <div class="container col-lg-4"> <?php echo validation_errors(); ?> <?php echo form_open('Welcome/gallery1'); ?>

我试图通过php CodeIgniter将数据插入数据库,并在提交按钮期间在同一页面中显示结果。下面是我的代码。问题是我没有从查看页面获取任何值,我检查了打印结果,结果是一个空数组。请帮忙。查看页面

<div class="container col-lg-4">
<?php echo validation_errors(); ?>
<?php echo form_open('Welcome/gallery1'); ?>                         
<div class="form-group has-info">
<input type="hidden" name="id" value="">
<br>
<label class="control-label col-lg-6" for="inputSuccess">Offer title
</label>
<input type="text" class="form-control col-lg-6" name="offered" value="<?php if(isset($_POST['offered'])) echo $_POST['offered'];  ?>" id="offered">
<label class="control-label col-lg-6" for="inputSuccess">Offer Description
</label>
<textarea id="description" name="description" value="<?php if(isset($_POST['description'])) echo $_POST['description'];  ?>" class="form-control col-lg-6"  rows="3" >
</textarea>
<br/>
<div>
<button type="submit" class="btn btn-primary col-lg-4">
<span>SUBMIT
</span>
</button>  
</div> 
</div>
<?php echo form_close(); ?>
</div>
模型页

<?php
class Login_set extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function add_offer($data1)
{
$this->load->database();
$this->load->helper('url');
if($this->db->insert('offer_hotel1',$data1))
return true;
else
return false;
}
}
?>

您不需要在HTML输入中保存任何值。简单地做:

<div class="container col-lg-4">
<?php echo validation_errors(); ?>
<?php echo form_open('Welcome/gallery1'); ?>
<div class="form-group has-info">
    <input type="hidden" name="id" value="">
    <br>
    <label class="control-label col-lg-6" for="inputSuccess">Offer title</label>
    <input type="text" class="form-control col-lg-6" name="offered" id="offered">
    <label class="control-label col-lg-6" for="inputSuccess">Offer Description</label>
    <textarea id="description" name="description" class="form-control col-lg-6"  rows="3" ></textarea>
    <br/>
    <div>
    <button type="submit" class="btn btn-primary col-lg-4">
    <span>SUBMIT</span>
    </button>
    </div>
</div>
<?php echo form_close(); ?>
值将作为
$this->input->post('description')转储到控制器中$此->输入->发布(“提供”)


如果您想查看此输入中是否已经设置了值,则需要从数据库中获取数据,而不是执行
value=“

,但我不会将值插入数据库。您正在执行$this->db->insert('offer_hotel1',$data1'),不插入是什么意思?当我提交按钮时,代码不起作用,然后值也被插入到数据库中,那么你想做什么呢
<div class="container col-lg-4">
<?php echo validation_errors(); ?>
<?php echo form_open('Welcome/gallery1'); ?>
<div class="form-group has-info">
    <input type="hidden" name="id" value="">
    <br>
    <label class="control-label col-lg-6" for="inputSuccess">Offer title</label>
    <input type="text" class="form-control col-lg-6" name="offered" id="offered">
    <label class="control-label col-lg-6" for="inputSuccess">Offer Description</label>
    <textarea id="description" name="description" class="form-control col-lg-6"  rows="3" ></textarea>
    <br/>
    <div>
    <button type="submit" class="btn btn-primary col-lg-4">
    <span>SUBMIT</span>
    </button>
    </div>
</div>
<?php echo form_close(); ?>
public function gallery1()
{
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->model('Login_set');
    $data1 = array(
        'offer_id'          =>$this->input->post('id'),
        'hotel_id'          =>1,
        'offers_name'       =>$this->input->post('offered'),
        'offers_description'=>$this->input->post('description')
    );
    print_r($data1);
    $this->Login_set->add_offer($data1);
    $page_id =$this->uri->segment(3);
    $data['h']=$this->Login_set->select();
    $this->load->view('App_stay/pages/hotel1_galery.php',$data);
}