javascript - 如何在 codeigniter 中使用同名的多个输入插入数据

标签 javascript php codeigniter

我使用 JavaScript 会产生以下条目

<input type="hidden" name="my_img[]" value="dad6e52b274690409835.jpg">
<input type="hidden" name="my_img[]" value="252529b6e21f872c7675.jpg">
<input type="hidden" name="my_img[]" value="3cce4128c366216fsfaf.jpg">
<input type="hidden" name="my_img[]" value="48697e8516caa3cc15d4.jpg">

但是我在将它们插入数据库时​​遇到了问题

我的 Controller :

   $dd=$this->input->post('my_img');
   for($i=0;$i<count($dd);$i++)
   {
   $img_box[$i] = array ('img_url' => $dd[$i]);
   }
   $this->posts_model->add_new_ads_img($img_box);

我的模型:

public function add_new_ads_img($img_box)
{
    $q = $this->db->insert('advertise_gallery',$img_box);
    if ($q)
    {
        return TRUE;
    }
    else return FALSE;
}

吃错了

严重性:注意

消息: undefined variable :img_box

请指导我

最佳答案

错误可能是您 Controller 中的这一行:

$img_box[$i] = array ('img_url' => $dd[$i]);

就在您的 for 循环之前添加:

$img_box = [];

关于javascript - 如何在 codeigniter 中使用同名的多个输入插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35508878/

相关文章:

javascript - Grunt.js 连接并中断 angular.js 项目?

PHP/MySQL : optimize query

php - 如何使用 CodeIgniter 框架从数组中插入多行?

php - 如何修复 "mysqli::real_connect(): SSL operation failed"错误?

php - Symfony2 Sonata Media Bundle——上传图片时出错

php - CodeIgniter 删除给定数组中的 where 条件和 where not

codeigniter - 我应该将验证 $_POST 值保存到变量中还是不保存在 CI 中?

javascript - 为什么我在这个循环中总是得到相同的输出?

javascript - 在 Firefox 中通过 Selenium 访问 ShadowRoot 返回 JavascriptException : Cyclic object value

javascript - Karma 测试期间,"Failed to execute ' querySelector ' on ' 文档 ': ' 类 MyComponent 扩展了 HTMLElement”