Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t使用Codeigniter更新数据库中的数据_Php_Mysql_Codeigniter - Fatal编程技术网

Php Can';t使用Codeigniter更新数据库中的数据

Php Can';t使用Codeigniter更新数据库中的数据,php,mysql,codeigniter,Php,Mysql,Codeigniter,我无法在CodeIgniter中更新记录中的数据。不是更新,而是在数据库表中添加新记录。“hotelres_id”是我的表的主键 我已将代码张贴在下面:- 要更新的控制器代码:- function edit($id){ $this->load->model('hotel_reservation','mb'); $data['message'] = ''; $data['object'] = $this->mb->find_by_id($id);

我无法在CodeIgniter中更新记录中的数据。不是更新,而是在数据库表中添加新记录。“hotelres_id”是我的表的主键

我已将代码张贴在下面:-

要更新的控制器代码:-

function edit($id){
    $this->load->model('hotel_reservation','mb');
    $data['message'] = '';
    $data['object'] = $this->mb->find_by_id($id);

    if($data['object']){
        $this->form_validation->set_rules('roomno', 'Room Number', 'required|is_unique[hotel_reservation.roomno]');
        $this->form_validation->set_rules('checkin', 'Check In', 'required|is_unique[hotel_reservation.checkin]');
        $this->form_validation->set_rules('checkout', 'Check Out', 'required|is_unique[hotel_reservation.checkout]');

        if ($this->form_validation->run() == TRUE){
            $this->mb->eventreg_id = $_POST['hotelres_id'];
            $this->mb->eventreg_id = $_POST['eventreg_id'];
            $this->mb->eventhotel_id = $_POST['eventhotel_id'];
            $this->mb->roomno = $_POST['roomno'];
            $this->mb->checkin = $_POST['checkin'];
            $this->mb->checkout = $_POST['checkout'];
            $this->mb->comment = $_POST['comment'];
            $this->mb->update();
            $data['message'] = 'Details updated successfully';
            $data['object'] = $this->mb;
        }
        $this->load->view('core/hotel_reservation/edit',$data);
    }
    else{
        $data['message'] = 'No details available!! Fill It!!';  
        $this->load->view('core/hotel_reservation/save',$data);
    }
}
查看代码:-

<html>
    <head>
    <title>Hotel Reservation</title>
    </head>
    <body>
        <h2>Hotel Reservation</h2>
        <?php if(isset($message)&&$message!='') echo "<span class=\"message\">{$message}</span>"; ?>
        <form action="<?php echo site_url('core/hotel_re/edit/'.@$object->hotelres_id); ?>" method="POST" >
            <table class="formtable">

            <tr><td>hotelres_id</td><td><input type="text" name="hotelres_id" id="hotelres_id"  class="textbox" value="<?php echo @$object->hotelres_id; ?>"  readonly></td></tr>
            <tr><td>eventreg_id</td><td><input type="text" name="eventreg_id" class="textbox" value="<?php echo @$object->eventreg_id; ?>"  readonly></td></tr>
            <tr><td>eventhotel_id</td><td><input type="text" name="eventhotel_id" class="textbox" value="<?php echo @$object->eventhotel_id; ?>" readonly></td></tr>


            <tr><td>Room Number</td><td><input type="text" name="roomno"  value="<?php echo @$object->roomno; ?>"  class="textbox" ></td></tr>
            <tr><td>Check In</td><td><input type="text"  name="checkin" value="<?php echo @$object->checkin; ?>"  class="textbox"></td></tr>

            <tr><td>Check Out</td><td><input type="text" name="checkout" value="<?php echo @$object->checkout; ?>"  class="textbox"></td></tr>

            <tr><td>Comment</td><td><textarea type="text"  name="comment" value="<?php echo @$object->comment; ?>"  class="textarea" ></textarea></td></tr>
            <tr><td>&nbsp;</td><td><input type="submit" name="submit" value="Update" class="submitbutton"></td></tr>
        </table>
    </form>
    <span class="validation-errors"><?php echo validation_errors(); ?></span>
    </body>
</html>

酒店预订
酒店预订

根据您的代码(
$this->mb->update();
),它正在调用mb模型。但是您已经提供了酒店预订模型的代码。可能有一些不匹配。

从我看到的情况来看,我认为您的问题在于这一行:

$this->db->update(self::$tablename,$this);
由于您应该向更新函数传递一个数组,其中包含要更新的TB列和值的匹配键,因此您发送整个对象($this),而不发送tableid和tablename?

错误就在这里

在您的控制器中,您已完成此操作

        $this->mb->eventreg_id = $_POST['hotelres_id'];
        $this->mb->eventreg_id = $_POST['eventreg_id'];
这应该是这个

        $this->mb->hotelres_id = $_POST['hotelres_id'];
        $this->mb->eventreg_id = $_POST['eventreg_id'];
就像我说的,更新术语应该这样写

$this->db->where($tableid,$this->hotelres_id);

已解决?

不应该使用此
$this->db->where($tableid,$this->$tableid)这是
$this->db->where($tableid,$this->$hotelres\u id)function@kakashihatake2不,它不工作……我已经在$tableid中存储了hotelres_id。给我一个错误未定义的符号$hotelres_id。在回答此问题之前,请阅读此内容…:|在这个问题上,我给了你-1?希望你得到你的答案:)是的,它正在工作:)…谢谢…但是只有“$this->mb->hotelres\u id=$\u POST['hotelres\u id'];”这个更正是必需的…这个“$this->db->where($tableid,$this->$hotelres\u id);”它给出了和我上面说的一样的错误…未定义..但是现在工作很好,谢谢againI理解,是的,它不起作用了。。。我在做这个
$this->$hotelres\u id
,而不是
$this->hotelres\u id
。。。实际上,where函数应该是我让你写的。只是有一个“
$
符号”的错误。因此,请使用我在回答中编辑的更新行,以便您的
hotelres\u id
能够在表中找到与发送给控制器的
$this->hotelres\u id
值匹配的值。很高兴帮助:)是的,它能工作。实际上上次我试过它…但由于另一个错误,它不能工作。
$this->db->where($tableid,$this->hotelres_id);