【问题标题】:Submit into database after choice radio button, Codeigniter 4选择单选按钮后提交到数据库,Codeigniter 4
【发布时间】:2021-12-17 01:58:11
【问题描述】:

我想从单选按钮选择中添加数据,但无法正确保存数据。我真的需要帮助。

查看代码

<?php echo form_open_multipart('home/saveCovid') ?>
<?php 
 for ($i=1; $i <=1; $i++){
 ?>
 <input type="radio" name="anotasi1<?php echo $i ? "" :     ($anotasi->anotasi == "Positif" ? "checked" : "") ?>" value="Positif">Positif<br>
                <input type="radio" name="anotasi1<?php echo $i ? "" : ($anotasi->anotasi == "Negatif" ? "checked" : "") ?>" value="Negatif">Negatif<br>
                <input type="radio" name="anotasi1<?php echo $i ? "" : ($anotasi->anotasi == "Netral" ? "checked" : "") ?>" value="Netral">Netral<br>
<?php
 }
  ?>
 </td>
 </tr>
        <?php } ?>
        
        </div>

控制器中的代码

public function saveCovid()
    {
       $data['anotasi1'] = $this->input->post('anotasi1');
    }

模型中的代码

protected $table = 'tbl_anotasi';
    
    public function alldata()
    {
        return $this->db->table('tbl_anotasi')->get()->getResultArray();
    }

    public function add($data)
    {
        $this->db->table('tbl_anotasi')->insert($data);
    }

【问题讨论】:

  • 您的控制器没有向模型发送任何数据。

标签: php radio-button codeigniter-4


【解决方案1】:

一行

$data['anotasi1'] = $this->input->post('anotasi1');

anotasi1 的值保存到名为$data 的数组中。虽然这可能很有用,但您真正需要的是通过调用模型的 add 方法来保存此值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 2015-01-20
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 2017-03-19
    • 2013-12-17
    相关资源
    最近更新 更多