gpt4 book ai didi

php - codeigniter 中的 'Student_Name' 中的未知列 'field list' 文件名 : E:/xampp/htdocs/codeIgniter/CodeIgniter-3. 1.4/system/database/DB_driver.php

转载 作者:行者123 更新时间:2023-11-28 23:16:05 24 4
gpt4 key购买 nike

我正在使用 CodeIgniter。我有一个在数据库中输入数据的表单,但我在这里遇到一个问题,说“codeigniter 中的 field list 中的未知列 Student_Name”。我已经尝试过,但到目前为止我无法解决。

这是我的代码。

查看文件Userinsert_view.php

<html>
<head>
<title>Insert Data Into Database Using CodeIgniter Form</title>
</head>
<body>

<div id="container">
<?php echo form_open('Userinsert_controller'); ?>
<h1>Insert Data Into Database Using CodeIgniter</h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<?php echo form_label('Student Name :'); ?> <?php echo form_error('dname'); ?><br />
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?><br />

<?php echo form_label('Student Email :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?><br />

<?php echo form_label('Student Mobile No. :'); ?> <?php echo form_error('dmobile'); ?><br />
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile', 'placeholder' => '10 Digit Mobile No.')); ?><br />

<?php echo form_label('Student Address :'); ?> <?php echo form_error('daddress'); ?><br />
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress')); ?><br />

<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">

</div>
</div>
</body>
</html>

Controller 文件Userinsert_controller.php

<?php

class Userinsert_controller extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->model('Userinsert_model');
}

function index() {
//Including validation library
$this->load->library('form_validation');

$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

//Validating Name Field
$this->form_validation->set_rules('dname', 'Username', 'required|min_length[5]|max_length[15]');

//Validating Email Field
$this->form_validation->set_rules('demail', 'Email', 'required|valid_email');

//Validating Mobile no. Field
$this->form_validation->set_rules('dmobile', 'Mobile No.', 'required|regex_match[/^[0-9]{10}$/]');

//Validating Address Field
$this->form_validation->set_rules('daddress', 'Address', 'required|min_length[10]|max_length[50]');

if ($this->form_validation->run() == FALSE) {
$this->load->view('Userinsert_view');
} else {
//Setting values for tabel columns
$data = array(
'Student_Name' => $this->input->post('dname'),
'Student_Email' => $this->input->post('demail'),
'Student_Mobile' => $this->input->post('dmobile'),
'Student_Address' => $this->input->post('daddress')
);
//Transfering data to Model
$this->Userinsert_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('Userinsert_view', $data);
}
}

}

?>

模型文件Userinsert_model.php

<?php

class Userinsert_model extends CI_Model{

function __construct() {
parent::__construct();
}

function form_insert($data){
// Inserting in Table(students) of Database(college)
$this->db->insert('students', $data);
}
}

?>

最佳答案

您在将值传递给所需的数据库列时犯了一个错误。确保 $data 数组的键在数据库表中具有相同的列名:

 $data = array( 'Student_Name' => $this->input->post('dname'), 'Student_Email' => $this->input->post('demail'), 'Student_Mobile' => $this->input->post('dmobile'), 'Student_Address' => $this->input->post('daddress') );

您正在传递 Student_name 索引中的值,它必须存在于表中。注意区分大小写的列名称。

如果您仍然遇到这个问题,请告诉我。

关于php - codeigniter 中的 'Student_Name' 中的未知列 'field list' 文件名 : E:/xampp/htdocs/codeIgniter/CodeIgniter-3. 1.4/system/database/DB_driver.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43829182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com