在实时服务器

时间:2016-06-15 03:04:40

标签: php codeigniter

我有一个表单发送到ajax,它在localhost中工作正常,但它在上传到服务器时给我错误: model / Excel.php中第29行的错误。这是第29行$this->db->insert('update',$data_user)

我找不到错误。请帮忙..

A Database Error Occurred

Error Number: 1062

Duplicate entry '0' for key 'PRIMARY'

INSERT INTO `request` (`email`, `name`, `phone`, `status`, `filename_user`) VALUES ([email protected]', 'tes email', '436354', '0', '5760c25d7fa87.xlsx')

Filename: models/Excel.php

Line Number: 29

Excel模型:

function tambahuser($data_user)
{
  $this->db->insert('request', $data_user);
  $this->db->insert_id();
            
  foreach ($data_user as $key)     
  {  
   $data = array(
     'email'  =>   $this->input->post('email'),
     'from_name'  =>   $this->input->post('from_nama'),
     'from_phone' =>   $this->input->post('from_phone')
   );
  }
}

控制器:

function undangan()
	{
		$this->load->library('session');
			$email          =   $this->input->post('email');
			$from_nama		=   $this->input->post('from_nama');
			$from_phone		=   $this->input->post('from_phone');

			$data_user = array(

				'email' => $email,
				'name'  => $from_nama,
				'phone' => $from_phone,
				'status'=> '0',
				'filename_user' => $this->session->xls, //upload filename
			    );

            $this->load->model('excel');
            
			$this->excel->tambahuser($data_user);
            $this->load->library('email_ses');
            $this->email_ses->send();
            
	        
		echo json_encode(array("email" => $email, "from_nama" => $from_nama,"from_phone" => $from_phone ));
	} 
}

表格:

<h4 id="form">Data Personal</h4>
<div class="col-sm-4">
   <input type="email" class="form-control input-lg" id="email"  name="email"  placeholder="Email" required>
</div>

<div class="col-sm-4">
   <input type="text" class="form-control input-lg"  id="from_nama" name="from_nama" placeholder="Nama" required>
</div>

<div class="col-sm-4">
   <input type="number" class="form-control input-lg"  id="from_phone"  name="from_phone" placeholder="Phone" required>
</div>
                            
<div class="row" id="button_pesan" align="center" style="display: none;">
  <button id="pesan" type="button" class="btn btn-download btn-md" onclick=pesan()>
     <span class="glyphicon glyphicon-send" aria-hidden="true" ></span>Pesan
  </button>
</div>

Ajax功能:

function pesan()
    { 
        email = $("#email").val(); 
        from_nama = $("#from_nama").val(); 
        from_phone = $("#from_phone").val(); 

        $.ajax
        ({
            url : "<?php echo site_url('kirim/undangan')?>/",
            type: "POST",
            dataType: "text",
            data:{from_nama: from_nama, email: email, from_phone: from_phone},
            success: function(data)
            {       
               $('#alert_sukses').show();
               $('#form_pesan').hide();
               $('#myModalLabel').hide();
               
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                alert('Error upload data');
            }

        });
    }

request结构:

enter image description here

0 个答案:

没有答案