Php 无法使用codeigniter在数据库中输入值
表单的验证工作正常,但当我尝试插入和提交时,数据没有存储在数据库中。我不明白我遇到了什么问题 php(控制器文件)Php 无法使用codeigniter在数据库中输入值,php,mysqli,model,controller,views,Php,Mysqli,Model,Controller,Views,表单的验证工作正常,但当我尝试插入和提交时,数据没有存储在数据库中。我不明白我遇到了什么问题 php(控制器文件) 联系_model.php(模型文件) 您尝试调试了什么?是否调用了saverecords?先生,我已经解决了这个问题,谢谢你回复我的帖子。你想和我们分享你的解决方案吗? <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Home extends
联系_model.php(模型文件)
您尝试调试了什么?是否调用了saverecords
?先生,我已经解决了这个问题,谢谢你回复我的帖子。你想和我们分享你的解决方案吗?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
//load database libray manually
$this->load->database();
//load Model
$this->load->model('Contact_model');
// load form and url helpers
$this->load->helper(array('form', 'url'));
// load form_validation library
$this->load->library('form_validation');
}
public function contact()
{
// Basic validation
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->helper('url');
$this->load->view('header');
$this->load->view('contact');
$this->load->view('footer');
}
else
{
/* load success template...
echo "Thanks For Contacting!";*/
//insert
if($this->input->post('submit'))
{
$name=$this->input->post('name');
$email=$this->input->post('email');
$subject=$this->input->post('subject');
$message=$this->input->post('message');
$this->Contact_model->saverecords($name,$email,$subject,$message);
echo "Records Saved Successfully";
}
}
}
}
?>
<?php
class Contact_model extends CI_Model
{
//Insert
function saverecords($name,$email,$subject,$message)
{
$query="insert into contact values('', '$name', '$email', '$subject', '$message')";
$this->db->query($query);
}
}
?>