Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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 Codeigniter-通过AJAX添加到数据库时出现内部服务器错误500&;jQuery_Php_Jquery_Mysql_Ajax_Codeigniter - Fatal编程技术网

Php Codeigniter-通过AJAX添加到数据库时出现内部服务器错误500&;jQuery

Php Codeigniter-通过AJAX添加到数据库时出现内部服务器错误500&;jQuery,php,jquery,mysql,ajax,codeigniter,Php,Jquery,Mysql,Ajax,Codeigniter,我在向数据库添加内容块时遇到问题,内容位于所见即所得编辑器中,我希望单击保存按钮,然后将内容通过jquery/ajax函数传递到控制器,并保存到我的数据库中供以后使用 我的数据库中的表是模板样式的模板,我希望在其中存储内容、一个自动递增的主键和Userstempid,Userstempid是模板的当前登录用户外键id 当我点击save按钮时,控制台中出现了一个内部服务器错误500,非常感谢您的帮助 我是新来的codeigniter,所以我不太确定我的查询等是否有问题,或者其他什么问题 我的视图-

我在向数据库添加内容块时遇到问题,内容位于所见即所得编辑器中,我希望单击保存按钮,然后将内容通过jquery/ajax函数传递到控制器,并保存到我的数据库中供以后使用

我的数据库中的表是模板样式的模板,我希望在其中存储内容、一个自动递增的主键和Userstempid,Userstempid是模板的当前登录用户外键id

当我点击save按钮时,控制台中出现了一个内部服务器错误500,非常感谢您的帮助

我是新来的codeigniter,所以我不太确定我的查询等是否有问题,或者其他什么问题

我的视图-所见即所得编辑器是trumbowyg演示和jquery ajax

<h5> Design Your Email </h5>
            <p>Use the editor below to design and fill in your email's content</p>
          <div id="trumbowyg-demo"></div>
          <h2 class="center light-blue-text">

 <button class="btn waves-effect waves-light center-align" type="submit" id="saveContent">Save Current Content
                      <i class="material-icons right">note_add</i>
   </button>



    $(document).ready(function(){

      $("#saveContent").click(function () {
          var content = $("#trumbowyg-demo").html();
          $.ajax({
              type: 'POST',
              url: "<?php echo site_url(); ?>/Dashboard/add",
              data: {
                  content: content
              },
              dataType: 'json',
              success: function (data) {
                  if (data.status == 'error') {
                      alert('An error occured: ' + data.msg);
                  } else {
                      alert(data.msg)
                  }
              }
          });
      });
My Model-Template_Model.php

        public function add(){

    $this->load->model('template_model');
        $this->template_model->AddTemplate();

         }
    class Template_model extends CI_Model {


      Public function AddTemplate(){
        $content = $this->input->post('templatestyle');,
        $user_id = $this->session->userdata('users_temp_id');
         $this->db->insert('templates', array('templatestyle' =>$content, 'users_temp_id'=>$user_id));
    }
始终首先创建数组(插入_数据)并将其作为参数传递

// your are sending 'content' not 'templatestyle' in ajax request
$content = $this->input->post('templatestyle');

// use this
$content = $this->input->post('content');
$user_id = $this->session->userdata('users_temp_id');
$insert_data = array(
                    'templatestyle'     => $content,
                    'users_temp_id' => $user_id,
                  );
$this->db->insert('templates',$insert_data);

请不要使用代码片段(仅)格式化您的代码,这是为了创建一个工作示例!你能粘贴你要返回的错误吗?@opticon我在控制台中收到“POST 500(内部服务器错误)”@plonknimbuzz no仍然收到相同的错误,并且没有添加到数据库中