doutan5337 2019-07-04 10:15
浏览 67

php codeigniter不要将变量更新为mysql

I have a problem with my PHP project with CodeIgniter.

I have a form in which I pass variables to the Database and execute an UPDATE Query by modifying the data on the Database.

The problem is that when I insert the new data it does not give me error, it shows me the view in which it shows the data of the table but the data are not modified.

Can anyone help me understand please?

MODELS 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."'");


Views update_records.php

<title>Registration form</title>

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

Controllers Hello.php

public function updatedata()

        echo "Success!";


I took the code from this tutorial

  • 写回答

1条回答 默认 最新

  • douzhan5058 2019-07-04 10:24

    i think problem in calling model function check:

    change this:




    and you change your custom query to CI query like:

    For Update


    For Select:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?
  • ¥15 在写pid调速的程序时,电机始终维持最大速度
  • ¥15 帅锅们,我很想知道这个论坛是用什么模板搭的(T_T)
  • ¥15 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素