Php 如何使用CodeIgniter编辑记录
我该如何编辑我的记录?我总是进入错误的页面。。提前谢谢你真的需要帮助吗 我把我的代码建立在我昨天得到的删除函数中,但我在编辑中没有这样做的运气 控制器Php 如何使用CodeIgniter编辑记录,php,html,codeigniter,edit,Php,Html,Codeigniter,Edit,我该如何编辑我的记录?我总是进入错误的页面。。提前谢谢你真的需要帮助吗 我把我的代码建立在我昨天得到的删除函数中,但我在编辑中没有这样做的运气 控制器 function update() { $booking=array( 'name'=>$this->input->post('name'), 'nationality'=>$this->input->post('nationality'), 'n
function update()
{
$booking=array(
'name'=>$this->input->post('name'),
'nationality'=>$this->input->post('nationality'),
'number_of_guest'=>$this->input->post('number_of_guest'),
'date'=>$this->input->post('date'),
'package'=>$this->input->post('package'),
'request'=>$this->input->post('request')
);
$this->site_model->update_record($booking);
$this->edit();
}
场地模型
function update_record($booking)
{
$this->db->where('id', 1);
$this->db->update('booking', $booking);
}
edit.php
<div id="bgbp"></div>
<div id="bp">
<h2 class="nb">Update</h2>
<?php echo form_open('site/update');?>
<div id="nems">
<p>
<label for="name"> Guest name(s): </label>
<input type="text" name="name" id="name" placeholder="Name(s)"/>
</p>
</div>
<div id="nat">
<p>
<label for="nationality">Nationality: </label>
<input type="text" name="nationality" id="nationality" placeholder="Nationality"/>
</p>
</div>
<div id="nog">
<p>
<label for="number_of_guest"> Number of Guest:</label>
<input type="number" name="number_of_guest" id="number_of_guest" placeholder="Number of Guest"/>
</p>
</div>
<div id="doa">
<p>
<label for="date"> Date of Arrival:</label>
<input type="date" name="date" id="date"/>
</p>
</div>
<div id="mainselection">
<select name="package" id="input7">
<option value="" style="display:none">Choose Package to avail</option>
<option value="Package A. Half - day City Tour">Package A. Half - day City Tour</option>
...
<option value="Package B. Honda Bay Island Hopping">Package B. Honda Bay Island Hopping</option>
<option value="Package C. St. Paul's Subterranean River National Park or Underground River">Package C. St. Paul's Subterranean River National Park or Underground River</option>
</select>
</div>
<div id="or">
<p>
<label for="request"> Other Request: </label>
<input type="comment" name="request" id="request" placeholder="Other Request"/>
</p>
</div>
<div id="sub">
<p>
<input type="submit" value="Submit" onclick="msg()" />
</p>
</div>
<?php echo form_close();?>
使现代化
客人姓名:
国籍:
客人人数:
抵达日期:
选择要使用的软件包
套餐A.半天城市旅游
...
B包本田湾岛酒店
包C.圣保罗地下河国家公园或地下河
其他要求:
我的查看页面…(显示我的编辑和删除按钮时)
在codeignitor中,您可以通过提供对表中现有记录的引用来更新任何记录
$this->db->update('booking', $booking);
booking
应该是要更新的表,$booking
必须是一个包含字段名和值的键/值对的数组
检查表的(booking
)字段名是否与$booking
中的键相同 您也可以用这种方式尝试
function update()
{
$booking=array(
'name'=>$this->input->post('name'),
'nationality'=>$this->input->post('nationality'),
'number_of_guest'=>$this->input->post('number_of_guest'),
'date'=>$this->input->post('date'),
'package'=>$this->input->post('package'),
'request'=>$this->input->post('request')
);
$this->db->where('id', 1);
$this->db->update('booking', $booking);
}
---------更新---
`函数更新()
{
$booking=数组(
'name'=>this->input->post('name'),
“国籍”=>$this->input->post('national'),
'number\u of_guest'=>this->input->post('number\u of_guest'),
'date'=>this->input->post('date'),
“包”=>this->input->post('package'),
“请求”=>$this->input->post('request')
);
$this->db->where(“”,);
$error=$this->db->update(“”,$booking);`,
请运行并粘贴您在$error
中获得的内容。请尝试此代码…这是我的代码,您可以根据需要进行更改
看法
控制器
function testimonials_edit($id)
{
$this->load->helper('form');
$this->load->helper('html');
$this->load->library('form_validation');
$this->load->model('testimonials_model');
$this->data=$this->testimonials_model->general();
$testimonials = $this->testimonials_model->get_testimonials($id);
$this->data['title'] = 'Edit Testimonial';
//validate form input
$this->form_validation->set_rules('title', 'Author', 'required|xss_clean');
$this->form_validation->set_rules('contentbox', 'content', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
if ($this->form_validation->run() === true)
{
$data = array(
'title'=>$this->input->post('title'),
'content'=> $this->input->post('contentbox'),
);
$this->testimonials_model->updatetestimonials($id, $data);
$this->session->set_flashdata('message', "<p>Testimonial is updated successfully.</p>");
redirect('testimonials_controller/testimonials_edit/'.$id);
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['testimonials'] = $testimonials;
//display the edit product form
$this->data['title'] = array(
'name' => 'title',
'id' => 'title',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('title', $testimonials['title']),
);
$this->data['content'] = array(
'name' => 'contentbox',
'id' => 'contentbox',
'type' => 'text',
'cols' => 60,
'rows' => 5,
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('contentbox',$testimonials['content']),
);
$this->load->view('testimonials_edit', $this->data);
}
功能证明\u编辑($id)
{
$this->load->helper('form');
$this->load->helper('html');
$this->load->library('form_validation');
$this->load->model(“推荐模型”);
$this->data=$this->commissional_model->general();
$estimationals=$this->estimationals\u model->get\u estimationals($id);
$this->data['title']=“编辑推荐信”;
//验证表单输入
$this->form_validation->set_规则('title'、'Author'、'required'xss_clean');
$this->form_validation->set_规则('contentbox','content','required | xss_clean');
如果(isset($\ U POST)和&!空($\ U POST))
{
如果($this->form\u validation->run()==true)
{
$data=数组(
'title'=>this->input->post('title'),
'content'=>this->input->post('contentbox'),
);
$this->推荐模型->更新时间($id,$data);
$this->session->set_flashdata('message',“证明文件已成功更新。”;
重定向('Certificationals_controller/Certificationals_edit/'。$id);
}
}
$this->data['message']=(验证错误()?验证错误():$this->session->flashdata('message');
$this->data['estimonials']=$estimonials;
//显示编辑产品表单
$this->data['title']=数组(
“名称”=>“标题”,
'id'=>'title',
'类型'=>'文本',
'样式'=>'宽度:300px;',
'value'=>$this->form_validation->set_value('title',$commentials['title']),
);
$this->data['content']=数组(
'name'=>'contentbox',
'id'=>'contentbox',
'类型'=>'文本',
'cols'=>60,
“行”=>5,
'样式'=>'宽度:250px;',
'value'=>$this->form\u validation->set\u value('contentbox',$commentials['content']),
);
$this->load->view('commissional_edit',$this->data);
}
我不明白..你能在我的代码中指定我应该编辑的地方吗?我真的很新,所以是的..在你的网站模型代码中,请打印预订数组($booking
)并检查数组$booking
中的键名是否与数据库中表booking
的字段名相同。例如:$booking
中的number\u of_guest
与数据库中的number\u of_guest
完全一致。匹配字符串?而不是函数更新(){$booking=array('name'=>$this->$input->post('name'),'nationality'=>this->input->post('nationality'),'number\u of theu guest'=>this->input->post('date'),'package'=>this->input->post('package'),'request'=>this->input->post('request');$this->site\u model->update\u记录('booking);
,您应该使用CodeIgniter表单验证。
` function update()
{
$booking=array(
'name'=>$this->input->post('name'),
'nationality'=>$this->input->post('nationality'),
'number_of_guest'=>$this->input->post('number_of_guest'),
'date'=>$this->input->post('date'),
'package'=>$this->input->post('package'),
'request'=>$this->input->post('request')
);
$this->db->where('<primary_key>', <pri_key_value>);
$error = $this->db->update('<table_name>', $booking);`,
<?php $id = "1" ?>
<?php echo form_open_multipart("testimonials_controller/testimonials_edit/$id");?>
<table width="500" class="table" cellpadding="0" cellspacing="2" align="center">
<tr>
<td width="130" align="left">Author: </td>
<td><?php echo form_input($title); ?></td>
</tr>
<tr>
<td width="130" align="left">Content: </td>
<td><?php echo form_textarea($content); ?></td>
<script type="text/javascript">
CKEDITOR.replace( 'contentbox' );
</script>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('submit', 'Submit');?>
</td>
</tr>
</table>
<?php echo form_close();?>
function updatetestimonials($id, $data)
{
$this->db->where('id', $id);
$this->db->update('testimonials', $data);
}
function testimonials_edit($id)
{
$this->load->helper('form');
$this->load->helper('html');
$this->load->library('form_validation');
$this->load->model('testimonials_model');
$this->data=$this->testimonials_model->general();
$testimonials = $this->testimonials_model->get_testimonials($id);
$this->data['title'] = 'Edit Testimonial';
//validate form input
$this->form_validation->set_rules('title', 'Author', 'required|xss_clean');
$this->form_validation->set_rules('contentbox', 'content', 'required|xss_clean');
if (isset($_POST) && !empty($_POST))
{
if ($this->form_validation->run() === true)
{
$data = array(
'title'=>$this->input->post('title'),
'content'=> $this->input->post('contentbox'),
);
$this->testimonials_model->updatetestimonials($id, $data);
$this->session->set_flashdata('message', "<p>Testimonial is updated successfully.</p>");
redirect('testimonials_controller/testimonials_edit/'.$id);
}
}
$this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
$this->data['testimonials'] = $testimonials;
//display the edit product form
$this->data['title'] = array(
'name' => 'title',
'id' => 'title',
'type' => 'text',
'style' => 'width:300px;',
'value' => $this->form_validation->set_value('title', $testimonials['title']),
);
$this->data['content'] = array(
'name' => 'contentbox',
'id' => 'contentbox',
'type' => 'text',
'cols' => 60,
'rows' => 5,
'style' => 'width:250px;',
'value' => $this->form_validation->set_value('contentbox',$testimonials['content']),
);
$this->load->view('testimonials_edit', $this->data);
}