PHP:codeigniter中未更新组合框值
我有从数据库获取数据的某些产品的表视图,当我单击编辑时,有两个选项PHP:codeigniter中未更新组合框值,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有从数据库获取数据的某些产品的表视图,当我单击编辑时,有两个选项edit和delete,它显示特定的数据。 组合框中有两个类别,分别是比萨饼和三明治 默认情况下,选择了Pizza,并且数据库中的值也是Pizza,直到现在问题才开始,当我选择sandwich而不是Pizza时,数据库中的值不会得到更新 我在这个项目中使用了codeigniter框架,所以我希望在相同的框架中使用解决方案。 我在谷歌和其他很多地方搜索过,但运气不好,没有得到我想要的正确的解决方案 任何帮助都将不胜感激。先谢谢你 代
edit
和delete
,它显示特定的数据。组合框中有两个类别,分别是
比萨饼
和三明治
默认情况下,选择了Pizza
,并且数据库中的值也是Pizza
,直到现在问题才开始,当我选择sandwich
而不是Pizza
时,数据库中的值不会得到更新
我在这个项目中使用了codeigniter框架,所以我希望在相同的框架中使用解决方案。我在谷歌和其他很多地方搜索过,但运气不好,没有得到我想要的正确的解决方案 任何帮助都将不胜感激。先谢谢你 代码:控制器
function products_edit($product_id)
{
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('products_model');
$data=$this->products_model->general();
$product = $this->products_model->get_product($product_id);
$category['categories']=$this->products_model->get_category();
$this->data1['title'] = 'Edit Product';
//validate form input
$this->form_validation->set_rules('name', 'Product name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean');
$this->form_validation->set_rules('price', 'Price', 'required|xss_clean');
$this->form_validation->set_rules('is_featured', 'Is Featured', 'required|xss_clean');
$this->form_validation->set_rules('prorder', 'Order', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
$data1 = array(
'product_name'=> $this->input->post('name'),
'product_desc'=> $this->input->post('description'),
'product_category'=> $this->input->post('category'),
'extras'=> $this->input->post('extras'),
'price'=> $this->input->post('price'),
'is_featured'=> $this->input->post('is_featured'),
'prorder' => $this->input->post('order'),
);
if ($this->form_validation->run() === true)
{
$this->products_model->updateproducts($product_id, $data1);
$this->session->set_flashdata('message', "<p>Product updated successfully.</p>");
redirect('products_controller/products_edit/'.$product_id);
}
}
$this->data1['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data1['product'] = $product;
//$this->data1['category']=$category;
//display the edit product form
$this->data1['name'] = array(
'name' => 'name',
'id' => 'name',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('name', $product['product_name']),
);
$this->data1['description'] = array(
'name' => 'description',
'id' => 'description',
'type' => 'text',
'cols' => 40,
'rows' => 5,
'value' => $this->form_validation->set_value('description', $product['product_desc']),
);
$category1=$this->products_model->get_category();
$category1['value']=set_value('category',$product['product_category']);
$temp=array(
'1'=>$category1['value'],
);
$category1=array_diff($category1,$temp);
$category1['value']=set_value('category',$product['product_category']);
$this->data1['category']=$category1;
$this->data1['extras'] = array(
'value' => $this->form_validation->set_value('extras', $product['extras']),
);
$this->data1['price'] = array(
'name' => 'price',
'id' => 'price',
'type' => 'text',
'style' => 'width:40px;text-align: right',
'value' => $this->form_validation->set_value('price', $product['price']),
);
$this->data1['is_featured'] = array(
'name' => 'is_featured',
'id' => 'is_featured',
'type' => 'text',
'style' => 'width:40px;text-align: right',
'value' => $this->form_validation->set_value('isfeatured', $product['is_featured']),
);
$this->data1['prorder'] = array(
'name' => 'prorder',
'id' => 'prorder',
'type' => 'text',
'style' => 'width:40px;',
'value' => $this->form_validation->set_value('prorder', $product['prorder']),
);
$this->load->view('products_edit', $this->data1);
}
视图:
<?php $product_id = $product['product_id']; ?>
<?php echo form_open("products_controller/products_edit/$product_id");?>
<table width="500" border="1" cellpadding="0" cellspacing="2" align="center">
<tr>
<td width="130" align="right"> Product Name: </td>
<td><?php echo form_input($name); ?></td>
</tr>
<tr>
<td width="130" align="right"> Product Description: </td>
<td><?php echo form_textarea($description); ?></td>
</tr>
<tr>
<td align="right">Product Category:</td>
<td>
<?php echo form_dropdown("product_id",$category,'value')?>
</td>
</tr>
<tr>
<td align="right">Extras:</td>
<td><?php echo form_dropdown("product_id",$extras,"#","id='product_id'");?></td>
</tr>
<tr>
<td align="right">Price:</td>
<td><?php echo form_input($price); ?></td>
</tr>
<tr>
<td align="right">Is Featured:</td>
<td><?php echo form_input($is_featured); ?></td>
</tr>
<tr>
<td align="right">Order:</td>
<td><?php echo form_input($prorder); ?></td>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<?php echo form_close(); ?>
<?php echo form_open("products_controller/products_search");?>
<?php echo form_submit('submit', 'Back');?>
<?php echo form_close(); ?>
产品名称:
产品说明:
产品类别:
额外费用:
您能否发布您正在使用的代码,以便我们能够更好地了解数据库中的值是否没有更新?我的问题是:表格在哪里提交?控制台或日志中是否有任何错误?要更新的查询是什么样子的?@Bhadra很抱歉回复太晚,但我在问题中编辑了我的代码,请检查并提出任何解决方案。
<?php $product_id = $product['product_id']; ?>
<?php echo form_open("products_controller/products_edit/$product_id");?>
<table width="500" border="1" cellpadding="0" cellspacing="2" align="center">
<tr>
<td width="130" align="right"> Product Name: </td>
<td><?php echo form_input($name); ?></td>
</tr>
<tr>
<td width="130" align="right"> Product Description: </td>
<td><?php echo form_textarea($description); ?></td>
</tr>
<tr>
<td align="right">Product Category:</td>
<td>
<?php echo form_dropdown("product_id",$category,'value')?>
</td>
</tr>
<tr>
<td align="right">Extras:</td>
<td><?php echo form_dropdown("product_id",$extras,"#","id='product_id'");?></td>
</tr>
<tr>
<td align="right">Price:</td>
<td><?php echo form_input($price); ?></td>
</tr>
<tr>
<td align="right">Is Featured:</td>
<td><?php echo form_input($is_featured); ?></td>
</tr>
<tr>
<td align="right">Order:</td>
<td><?php echo form_input($prorder); ?></td>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<?php echo form_close(); ?>
<?php echo form_open("products_controller/products_search");?>
<?php echo form_submit('submit', 'Back');?>
<?php echo form_close(); ?>