使用编码器点火器更新记录时出错



我正在尝试更新存储在数据库中的记录,但不幸的是我收到诸如(如下所示)之类的错误,任何人都可以在这方面帮助我,这将对我有很大帮助

遇到 PHP 错误

严重性:通知

消息:未定义的属性:标准类::$id

文件名:视图/display_about_us1.php

行号:44

回溯:

文件: C:\xampp\htdocs\CodeIgniter_try\application\views\display_about_us1.php 行: 44

功能:_error_handler

文件: C:\xampp\htdocs\CodeIgniter_try\application\controllers\Home.php 行: 107 功能:查看

文件: C:\xampp\htdocs\CodeIgniter_try\index.php 行: 315 功能:require_once

控制器

public function updatedata()
{
$id=$this->input->get('id');
$result['data']=$this->Contact_model->displayrecordsById($id);
$this->load->view('update_about_us1',$result);  
if($this->input->post('update'))
{
// Basic validation
$this->form_validation->set_rules('first_content', 'First content', 'required');
$this->form_validation->set_rules('second_content', 'Second content', 'required');
$this->form_validation->set_rules('third_content', 'Third content', 'required');
$this->form_validation->set_rules('fourth_content', 'Fourth content', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('update_about_us1'); 
}
else
{
$id = $this->input->post('id');
$data = array();
$data['first_content']=$this->input->post('first_content');
$data['second_content']=$this->input->post('second_content');
$data['third_content']=$this->input->post('third_content');
$data['fourth_content']=$this->input->post('fourth_content');
$this->Contact_model->updaterecords($id, $data);
redirect("Home/About_us_display");
}
}
}

function displayrecordsById($id)
{
$query=$this->db->query("select * from about_us1 where id='".$id."'");
return $query->result();
}
function updaterecords($id,$data)
{
$this->db->where('id', $id);
$this->db->update('about_us1', $data);
}

视图

<!DOCTYPE html>
<html>
<head>
<title>About_us1 page</title>
</head>
<body>
<?php
$i=1;
foreach($data as $row)
{
?>
<form action="Home/updatedata" method="get">
<table width="600" border="1" cellspacing="5" cellpadding="5">
<tr>
<td width="230">First content </td>
<td width="329"><textarea rows="4" cols="50"  name="first_content" value="<?php echo $row->first_content; ?>"/></textarea></td>
<span><?php echo form_error("first_content");?></span>
</tr>
<tr>
<td>Second content </td>
<td><textarea rows="4" cols="50" name="second_content" value="<?php echo $row->second_content; ?>"/></textarea></td>
<span><?php echo form_error("second_content");?></span>
</tr>
<tr>
<td>Third content </td>
<td><textarea rows="4" cols="50" name="third_content" value="<?php echo $row->third_content; ?>"/></textarea></td>
<span><?php echo form_error("third_content");?></span>
</tr>
<tr>
<td>Fourth content </td>
<td><textarea rows="4" cols="50" name="fourth_content" value="<?php echo $row->fourth_content; ?>"/></textarea></td>
<span><?php echo form_error("fourth_content");?></span>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="update" value="Update Records"/></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>


// display record view page 

<!DOCTYPE html>
<html lang="en">
<head>
<title>display</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br><br>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading text-center">Contact Us Details</div>
</div>
<div class="table-responsive">          
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>First Content</th>
<th>Second Content</th>
<th>Third Content</th>
<th>Fourth Content</th>
<th>Update Content</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$i=1;
foreach($data as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->first_content."</td>";
echo "<td>".$row->second_content."</td>";
echo "<td>".$row->third_content."</td>";
echo "<td>".$row->fourth_content."</td>";
echo "<td><a href='updatedata?id=".$row->id."'>Update</a></td>";
echo "</tr>";
$i++;
}
?>
</tr>
</tbody>  
</table>
</div><br><br>
<a href="<?php echo site_url("Home/backend"); ?>" style="margin-left: 40%"> <button type="button" class="btn btn-success">Back</button></a>
</div>
</body>
</html>

希望这会对您有所帮助:

参数与带有模型的控制器中的updaterecords方法不匹配

应该是这样的:

在控制器中调用updaterecords方法,如下所示:

$this->Contact_model->updaterecords($id, $data);

您的模型方法应如下所示:

function updaterecords($id,$data,)
{
$this->db->where('id', $id);
$this->db->update('about_us1', $data);
}

更新:

您的控制器代码应如下所示:

if($this->input->post('update'))
{
$data = array();
$id = $this->input->post('id');
$data['first_content']=$this->input->post('first_content');
$data['second_content']=$this->input->post('second_content');
$data['third_content']=$this->input->post('third_content');
$data['fourth_content']=$this->input->post('fourth_content');
$this->Contact_model->updaterecords($id, $data);
redirect("Home/About_us_display");
}

相关内容

  • 没有找到相关文章

最新更新