gpt4 book ai didi

php - 使用 codeigniter 将数据插入数据库

转载 作者:行者123 更新时间:2023-11-29 20:59:30 25 4
gpt4 key购买 nike

我正在使用 php 在 codeigniter 中创建一个应用程序。我想将数据插入到数据库表中,其中数据在循环内的输入框中输入。到目前为止,我已经尝试了以下代码:

cms_model.php

public function loadadd($mekhala_Id){

$query = $this->db->get_where('tb_unit', array('mandalam_Id' => $mekhala_Id));
echo form_open('Payment/amount');
?>


<h1>Members List</h1>
<table border="1">
<tr>
<th>Unit</th>
<th>Unit Secretary</th>
<th>Amount paid</th>

</tr>
<?php
foreach ($query->result() as $row)
{
?>

<tr>
<td> <?php echo $row->unitName ;?></td>
<td> <?php echo $row->unit_sec ;?></td>
<td> <?php echo form_input(array('name'=>'na','placeholder'=>'Rupees Paid')) ;?></td>
</tr>
<?php

}

echo form_submit(array('name'=>'sub','value'=>'submit'));
echo form_close();
}



public function loadpayment($paid){

// $paid= $this->input->post('na');

$fieldsData = $this->db->field_data('tb_unit');
$datacc = array(); // you were setting this to a string to start with, which is bad

foreach ($fieldsData as $key => $field)
{
$datacc[ $field->Amount] = $this->input->post( $field->Amount);
}
$this->db->insert('tb_unit', $datacc);

}
// $this->db->set('Amount', $paid)




}




?>

我在运行此代码时遇到以下错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Amount

Filename: models/cms_model.php

Line Number: 110

请帮助我解决此错误。

最佳答案

将第 #110 行更改为:

$datacc[$field->name] = $this->input->post($field->name);

关于php - 使用 codeigniter 将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359642/

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