发生数据库错误
错误号码:1048
列'page_id'不能为空
INSERT INTO st_hit (page_id, hit_time) VALUES (NULL, 1486470765)
文件名:数据库\ DB_driver.php
行号:330
DB_Driver.php
if ($this->db_debug)
{
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();
// We call this function in order to roll-back queries
// if transactions are enabled. If we don't call this here
// the error message will trigger an exit, causing the
// transactions to remain in limbo.
$this->trans_complete();
// Log and display errors
log_message('error', 'Query error: '.$error_msg);
return $this->display_error(
array(
'Error Number: '.$error_no,
$error_msg,
$sql
)
); **(Line 330)**
同时如果我在表格st_hit上查看PHPMyAdmin,结构显示如下:
请告知我应该怎么做,因为它应该显示404页面未找到
除此之外,它还显示如下:
遇到PHP错误
严重性:注意
消息:尝试获取非对象的属性
文件名:controllers / page.php
行号:92
遇到PHP错误
严重性:注意
消息:尝试获取非对象的属性
文件名:controllers / page.php
我的控制器页面php文件是这样的:
类页面扩展了MY_Controller {
function __construct()
{
parent::__construct();
$this->load->model('media_model');
$this->load->library('website');
//$this->load->library('facebook');
$this->website->getConfig();
$this->load->library('analytics');
/*if ( ! $this->session->userdata('sess_visit'))
{*/
$this->analytics->getVisitor_data();
//$this->session->set_userdata('sess_visit', 1);
//}
}
private function getHit_Counter($page_id) {
if ($this->uri->segment(1) == 'admin')
return FALSE;
$hitCounter['page_id'] = $page_id;
$hitCounter['hit_time'] = strtotime(date("Y-m-d H:i:s"));
//print_r($hitCounter);
$this -> db -> insert("st_hit", $hitCounter);
}
function index()
{
$this->data['page_list_category'] = false;
$post_category = false;
$guid = $this->uri->segment(1);
$this->data['parent'] = 1;
if ($guid)
{
if ( ! $this->data['page_detail'] = $this->page_model->find_guid($guid, 'page'))
show_404();
/ if(!$ this-> data ['page_detail'] = $ this-> page_model-> find_guid($ guid,'page'))show_404 $ this-> data ['page_detail'] = $ this-> page_model-> find_id(1); /
$this->data['parent'] = $this->page_model->get_parent($this->data['page_detail']->page_id);
if ($this->data['parent']=='')
$this->data['parent'] = $this->page_model->get_nav_det($this->data['page_detail']->page_id);
}
else
{
$this->data['page_detail'] = $this->page_model->find_id(1);
/* $this->data['product_category'] = $this->page_model->get_extra_post(145,26);
$this->data['product_list'] = $this->page_model->get_post_by_cat($this->data['product_category'][0]->page_id,true);*/
$this->data['lightbox1'] = $this->page_model->get_lightbox(4);
$this->data['lightbox2'] = $this->page_model->get_lightbox(5);
$this->data['lightbox3'] = $this->page_model->get_lightbox(6);
/* $this->data['lightbox4'] = $this->page_model->get_lightbox(5);
$this->data['lightbox5'] = $this->page_model->get_lightbox(6);
$this->data['lightbox6'] = $this->page_model->get_lightbox(7);
$this->data['lightbox7'] = $this->page_model->get_lightbox(8);
$this->data['lightbox8'] = $this->page_model->get_lightbox(9);
$this->data['lightbox9'] = $this->page_model->get_lightbox(10); */
/*$this->data['home_news'] = $this->page_model->get_archieve(18, false, 3, 0);
$this->data['post_testi'] = $this->page_model->get_testi_post(1);
$this->data['post_news'] = $this->page_model->get_child_post(134, 'post');
$this->data['recipe_week'] = $this->page_model->get_archieve(104, false, 1, 0);
$this->data['home_testi'] = $this->page_model->limit_result(3, 0); */
$this->getHit_Counter(1);
$this->website->page_id = 1;
}
$this->data['page_post'] = $this->page_model->get_child_post($this->data['page_detail']->page_id, 'post');
$this->data['page_banner'] = $this->page_model->get_child_post($this->data['page_detail']->page_id, 'banner');
$this->data['page_pbanner'] = $this->page_model->get_child_post($this->data['page_detail']->page_id, 'pbanner');
$this->data['page_category'] = $this->page_model->get_child_post($this->data['page_detail']->page_id, 'category');
if ($this->uri->segment(3) == 'apply')
{
$this->data['post_detail'] = $this->page_model->guid_checking($this->uri->segment(2));
$this->getHit_Counter($this->data['post_detail']->page_id);
$this->template->build('page_career_apply', $this->data);
return false;
}
if ($this->uri->segment(2) != '' AND $this->uri->segment(2) != 'archive' AND $this->uri->segment(2) != 'page')
{
$guid = $this->uri->segment(2);
if (!$type = $this->page_model->guid_checking($guid)) {show_404();}
if ($type->template_type=='post')
{
$this->data['page_detail'] = $this->page_model->get_child_post_by_guid($guid, 'post');
$post_category = $this->page_model->get_category_id($this->data['page_detail']->page_id);
if ($post_category)
{
$cat = array();
foreach ($post_category as $p_cat){
$cat[] = $p_cat->category_id;
}
$allcat = implode(',', $cat);
$this->data['random_post'] = $this->page_model->get_random_by_cat($allcat);
}
}
if ($type->template_type=='category')
{
$this->data['page_list_category'] = $this->page_model->get_post_by_cat($type->page_id);
}
}
if ($this->data['page_detail']->page_guid == 'testimoni')
{
$this->data['post_testi'] = $this->page_model->get_testi_post();
}
if ($this->data['page_detail']->page_sidebar == 'Visible' AND $this->data['page_detail']->sidebar_id != 0)
{
$sidebar_id = $this->data['page_detail']->sidebar_id;
$this->data['sidebar_detail'] = $this->page_model->get_sidebar($sidebar_id);
}
if ($this->data['page_detail']->template_id==13)
{
$this->data['rarchive'] = $this->page_model->get_archive(14);
}
$this->getHit_Counter($this->data['page_detail']->page_id);
/*meta*/
$this->website->page_id = $this->data['page_detail']->page_id;
$this->website->getConfig();
/*end meta*/
$this->template->build($this->data['page_detail']->template_body, $this->data);
}
function listproduct()
{
$id = $this->uri->segment(4);
$this->data['product_list'] = $this->page_model->get_post_by_cat($id,true);
$this->load->view('page_pp', $this->data);
}
public function sendtestimonial()
{
$alert = array(
'alert_state' => 'fail',
'alert_message' => 'An error occurred.'
);
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'name', 'trim|required|strip_tags');
$this->form_validation->set_rules('message', 'message', 'trim|required|strip_tags');
if ($this->form_validation->run())
{
$data = array(
'page_id' => '179',
'comment_author' => $this->input->post('name'),
'comment_content' => $this->input->post('message'),
'comment_created' => time(),
'comment_status' => 'Draft'
);
if ($this->page_model->saveTestimonial($data))
{
echo "$('.loading').hide();
$('#alert').hide();
$('.succ-msg').addClass('errorMessage').show().fadeIn(300).html('Your testimonial has been successfully sent.').fadeOut(5000);
document.getElementById('testiForm').reset();";
exit;
}
else
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Somethings missing. Please try again.').fadeOut(5000);
document.getElementById('testiForm').reset();";
exit;
}
}
else
{
if ($this->input->is_ajax_request())
{
$error = '';
if (form_error('name'))
$error = 'name';
else if (form_error('message'))
$error = 'message';
if ($error=='message'){
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');
$('input').css({'border-color':'#dddddd'});
$('textarea').css({'border-color':'#dddddd'});
$('textarea[name=\"" . $error . "\"]').css({'border':'1px solid #ae1f26'});";
exit;
} else {
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');
$('input').css({'border-color':'#dddddd'});
$('textarea').css({'border-color':'#dddddd'});
$('input[name=\"" . $error . "\"]').css({'border':'1px solid #ae1f26'});";
exit;
}
}
}
}
public function sendcontact()
{
$alert = array(
'alert_state' => 'fail',
'alert_message' => 'An error occurred.'
);
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'name', 'trim|required|strip_tags');
$this->form_validation->set_rules('phone', 'phone', 'trim|required|strip_tags');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->form_validation->set_rules('message', 'message', 'trim|required|strip_tags');
if ($this->form_validation->run())
{
if ($this->input->is_ajax_request())
{
/* SEND MAIL */
$this->load->library('email');
$system_info_email = $this->page_model->find_id(24)->page_email;
$this->email->from($this->input->post('email'));
$this->email->to($system_info_email);
$this->email->subject('Sekarbumi Contact Us Form');
$this->email->set_mailtype('html');
$msg = "Name : ". $this->input->post('name');
$msg .= "<br/>Email : ". $this->input->post('email');
$msg .= "<br/>Phone : ". $this->input->post('phone');
$msg .= "<br/><br/>Message : <br/>";
$msg .= $this->input->post('message');
$this->email->message($msg);
if($this->email->send())
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Your message has been successfully sent and wait for replay.').fadeOut(5000);
document.getElementById('contactForm').reset();";
exit;
}
else
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Error Occurred. Try again later.').fadeOut(5000);
document.getElementById('contactForm').reset();";
exit;
}
}
}
else
{
if ($this->input->is_ajax_request())
{
$error = "$('input').removeClass('error');$('textarea').removeClass('error');$('.loading').hide();$('#alert').addClass('errorMessage').show().fadeIn(300).html('Sorry. Please Fill All Fields.');";
if (form_error('name'))
$error .= "$('input[name=\"name\"]').addClass('error');";
if (form_error('phone'))
$error .= "$('input[name=\"phone\"]').addClass('error');";
if (form_error('email'))
$error .= "$('input[name=\"email\"]').addClass('error');";
if (form_error('message'))
$error .= "$('textarea[name=\"message\"]').addClass('error');";
echo $error;
exit;
}
}
}
public function sendform()
{
$alert = array(
'alert_state' => 'fail',
'alert_message' => 'An error occurred.'
);
$this->load->library('form_validation');
$this->form_validation->set_rules('full_name', 'full_name', 'trim|required|strip_tags');
$this->form_validation->set_rules('gender', 'gender', 'trim|required|strip_tags');
$this->form_validation->set_rules('date', 'date', 'trim|required|strip_tags');
$this->form_validation->set_rules('month', 'month', 'trim|required|strip_tags');
$this->form_validation->set_rules('year', 'year', 'trim|required|strip_tags');
$this->form_validation->set_rules('address', 'address', 'trim|required|strip_tags');
$this->form_validation->set_rules('phone', 'phone', 'trim|required|strip_tags');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->form_validation->set_rules('education', 'education', 'trim|required|strip_tags');
$this->form_validation->set_rules('about', 'about', 'trim|required|strip_tags');
$max = $this->input->post('numexp');
for($i=1;$i<=$max;$i++)
{
$this->form_validation->set_rules('fromperiode'.$i, 'fromperiode'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('untilperiode'.$i, 'untilperiode'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('company'.$i, 'company'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('position'.$i, 'position'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('jobdesc'.$i, 'jobdesc'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('salary'.$i, 'salary'.$i, 'trim|strip_tags');
$this->form_validation->set_rules('rol'.$i, 'rol'.$i, 'trim|strip_tags');
}
if ($this->form_validation->run())
{
$pathToUploadedFile = '';
$config['upload_path'] = './assets/attach/';
$config['allowed_types'] = 'doc|docx|pdf|jpg|png|jpeg';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('upload_cv'))
{
$ret = $this->upload->data();
$pathToUploadedFile = $ret['full_path'];
}
/* SEND MAIL */
$this->load->library('email');
$system_info_email = $this->page_model->find_id(180)->page_email;
$this->email->from($this->input->post('email'), $this->input->post('full_name'));
$this->email->to($system_info_email);
$this->email->subject('Job Application');
if ($pathToUploadedFile != '')
{
$this->email->attach($pathToUploadedFile);
}
$this->email->set_mailtype('html');
$msg = "Full Name : ". $this->input->post('full_name');
$msg .= "<br/>Gender : ". $this->input->post('gender');
$msg .= "<br/>Date of Birth : ". $this->input->post('date') .'-'. $this->input->post('month') .'-'. $this->input->post('year');
$msg .= "<br/>Address : ". $this->input->post('address');
$msg .= "<br/>Phone : ". $this->input->post('phone');
$msg .= "<br/>Email : ". $this->input->post('email');
$msg .= "<br/>Education : ". $this->input->post('education');
$msg .= "<br/>About : <br/>";
$msg .= $this->input->post('about');
$msg .= "<br/><br/>Last Job<br/><br/>";
$max = $this->input->post('numexp');
for($i=1;$i<=$max;$i++)
{
$msg .= "Periode : ". $this->input->post('fromperiode'.$i)." - ".$this->input->post('untilperiode'.$i);
$msg .= "<br/>Company : ". $this->input->post('company'.$i);
$msg .= "<br/>Position : ". $this->input->post('position'.$i);
$msg .= "<br/>Job Description : ". $this->input->post('jobdesc'.$i);
$msg .= "<br/>Salary : ". $this->input->post('salary'.$i);
$msg .= "<br/>Reason of Leaving : <br/>";
$msg .= $this->input->post('rol'.$i)."<br/><br/>";
}
$this->email->message($msg);
if($this->email->send())
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Thank you. Your job application has been successfully sent.').fadeOut(5000);
document.getElementById('contactForm').reset();";
exit;
}
else
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Error occurred, please try again later.').fadeOut(5000);
document.getElementById('careerForm').reset();";
exit;
}
}
else
{
if ($this->input->is_ajax_request())
{
$error = '';
if (form_error('full_name'))
{$error = 'full_name';$name = 'full_name';}
else if (form_error('gender'))
{$error = 'gender';$name = 'gender';}
else if (form_error('date'))
{$error = 'date';$name = 'date';}
else if (form_error('month'))
{$error = 'month';$name = 'month';}
else if (form_error('year'))
{$error = 'year';$name = 'year';}
else if (form_error('address'))
{$error = 'address';$name = 'address';}
else if (form_error('phone'))
{$error = 'phone';$name = 'phone';}
else if (form_error('email'))
{$error = 'email';$name = 'email';}
else if (form_error('about'))
{$error = 'about';$name = 'about';}
/* else if (form_error('periode'))
{$error = 'periode';$name = 'periode';}
else if (form_error('company'))
{$error = 'company';$name = 'company';}
else if (form_error('position'))
{$error = 'position';$name = 'position';}
else if (form_error('jobdesc'))
{$error = 'jobdesc';$name = 'jobdesc';}
else if (form_error('salary'))
{$error = 'salary';$name = 'salary';}
else if (form_error('rol'))
{$error = 'reason of leaving';$name = 'rol';} */
if ($error == 'about')
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');
$('select').parent().find('.select').css({'border-color':'#dddddd'});
$('input').css({'border-color':'#dddddd'});
$('textarea').css({'border-color':'#dddddd'});
$('textarea[name=\"" . $name . "\"]').css({'border':'1px solid #ae1f26'});";
exit;
}
else if ($error == 'date' || $error == 'month' || $error == 'year')
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');
$('select').parent().find('.select').css({'border-color':'#dddddd'});
$('input').css({'border-color':'#dddddd'});
$('textarea').css({'border-color':'#dddddd'});
$('select[name=\"" . $name . "\"]').parent().find('.select').css({'border':'1px solid #ae1f26'});";
exit;
}
else
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');
$('select').parent().find('.select').css({'border-color':'#dddddd'});
$('input').css({'border-color':'#dddddd'});
$('textarea').css({'border-color':'#dddddd'});
$('input[name=\"" . $name . "\"]').css({'border':'1px solid #ae1f26'});";
exit;
}
}
}
}
public function search()
{
if ($_POST)
{
$keyword = trim($this->input->post('search', TRUE));
redirect('search/' . urlencode(str_replace(array('/','\\','"'), '', $keyword)));
}
$key = $this->uri->segment(2);
$keyword = urldecode($key);
$search_result = $this->page_model->search_result($keyword);
/* $total_rows = count($search_result);
$page = $this->uri->segment(5);
$limit = 10;
if ( ! $page OR ! $this->page_model->is_natural_no_zero($page))
{
$page = 1;
$offset = 0;
}
else
{
if ($total_rows > $limit AND $page > ceil($total_rows / $limit))
$page = ceil($total_rows / $limit);
$offset = ($page * $limit) - $limit;
}
$this->load->library('pagination');
$config['base_url'] = site_url('search/' . $key . '/page' );
$config['total_rows'] = $total_rows;
$config['per_page'] = $limit;
$config['uri_segment'] = 5;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<ul class="pagination reset">';
$config['full_tag_close'] = '</ul>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_link'] = '<li><img src="'.site_url("themes/ranchs/assets/images/left-arrow.png").'" style="vertical-align:middle;" /> prev</li>';
$config['next_link'] = '<li>next <img src="'.site_url("themes/ranchs/assets/images/right-arrow.png").'" style="vertical-align:middle;" /></li>';
$config['first_link'] = FALSE;
$config['last_link'] = FALSE;
$config['num_links'] = $total_rows;
$this->pagination->initialize($config);
$this->data['links'] = $this->pagination->create_links();
$first_data = ($page * $limit)-9;
$last_data = ($page * $limit);
if ($last_data > $total_rows) $last_data = $total_rows;
$this->data['search_result'] = $this->page_model->search_result($keyword, $limit, $offset);
$this->data['total_rows'] = $search_result;
$this->data['total_rows_count'] = $total_rows;
$this->data['first_data'] = $first_data;
$this->data['last_data'] = $last_data;
$this->data['keyword'] = $keyword; */
$this->data['search_result'] = $this->page_model->search_result($keyword);
$this->data['keyword'] = $keyword;
$this->template->build('search', $this->data);
}
public function newsletter()
{
$alert = array(
'alert_state' => 'fail',
'alert_message' => 'An error occurred.'
);
$this->load->library('form_validation');
$this->form_validation->set_rules('newsletter', 'newsletter', 'trim|required|valid_email');
if ($this->form_validation->run())
{
if ($this->input->is_ajax_request())
{
$data = array(
'newsletter_email' => $this->input->post('newsletter'),
'newsletter_Status' => 'Published'
);
if ($this->page_model->cek_newsletter($this->input->post('newsletter')))
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Your email already saved. Please input different email.');
document.getElementById('newsletterForm').reset();";
exit;
}
else if ($this->page_model->regis_newsletter($data))
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Your email has been successfully saved.');
document.getElementById('newsletterForm').reset();";
exit;
}
else
{
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('Somethings missing. Please try again.');
document.getElementById('newsletterForm').reset();";
exit;
}
}
}
else
{
if ($this->input->is_ajax_request())
{
$error = '';
if (form_error('newsletter'))
$error = 'newsletter';
echo "$('.loading').hide();
$('#alert').addClass('errorMessage').show().fadeIn(300).html('" . form_error($error) . "');";
exit;
}
}
}
public function signin()
{
$this->load->view('signin_index', $this->data);
}
public function signindetail()
{
$this->load->view('under_construction', $this->data);
}
}
感谢。
答案 0 :(得分:0)
您应该使列Allow NULL
向其中插入空值。
运行以下查询
ALTER TABLE `st_hit` CHANGE `page_id` `page_id` INT(10) NULL;