gpt4 book ai didi

php codeigniter 不更新变量到 mysql

转载 作者:行者123 更新时间:2023-11-29 15:48:51 24 4
gpt4 key购买 nike

我的 CodeIgniter PHP 项目出现问题。

我有一个表单,可以将变量传递到数据库并通过修改数据库上的数据来执行更新查询。

问题是,当我插入新数据时,它不会给我错误,它会向我显示显示表数据但数据未修改的 View 。

谁能帮我理解一下吗?

模型 Hello_Model.php

function displayrecordsById($id)
{
$query=$this->db->query("SELECT * FROM Todolist WHERE id='".$id."'");
return $query->result();
}

function updaterecords($testo,$stato,$id)
{
$this->db->query("update Todolist SET testo='$testo',stato='$stato' WHERE id='".$id."'");

}

浏览次数 update_records.php

<html>
<head>
<title>Registration form</title>
</head>

<body>
<?php
//$i=1;
foreach($data as $row)
{
?>
<form method="post">
<table width="600" border="1" cellspacing="5" cellpadding="5">
<tr>
<td width="230">Id </td>
<td width="329"><input type="text" name="id" value="<?php echo $row->id; ?>"/></td>
</tr>
<tr>
<td>Testo </td>
<td><input type="text" name="testo" value="<?php echo $row->testo; ?>"/></td>
</tr>
<tr>
<td>Stato</td>
<td><input type='text' name='stato' value= "<?php echo $row->stato; ?> "/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="update" value="Update Records"/></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>
</html>

Controller Hello.php

public function updatedata()
{
$id=$this->input->get('id');
$result['data']=$this->Hello_Model->displayrecordsById($id);
$this->load->view('update_records',$result);

if($this->input->post('update'))
{
$n=$this->input->post('testo');
$e=$this->input->post('stato');
$this->Hello_Model->updaterecords($id,$n,$e);
redirect("http://simone.fabriziolerose.it/index.php/Hello/dispdata");
echo "Success!";

}
}

我从 this 获取了代码教程

最佳答案

我认为调用模型函数检查有问题:

更改此:

$this->Hello_Model->updaterecords($id,$n,$e);

 $this->Hello_Model->updaterecords($n,$e,$id);

然后将自定义查询更改为 CI 查询,例如:

更新

$this->db->where("id",$id);
$this->db->update("Todolist",array("testo"=>$testo,"stato"=>$stato));

对于选择:

$this->db->where("id",$id);
$query=$this->db->get("Todolist");
$row=$query->row();

关于php codeigniter 不更新变量到 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56885731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com