Forms Codeigniter如何将表单中的数据保存到数据库

Forms Codeigniter如何将表单中的数据保存到数据库,forms,codeigniter,send,Forms,Codeigniter,Send,共点火器 嗨。我想将表单数据发送到数据库。数据检查正常,但下一步怎么办 我的控制 <?php class Form extends CI_Controller { function index() { $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->

共点火器

嗨。我想将表单数据发送到数据库。数据检查正常,但下一步怎么办

我的控制

 <?php

class Form extends CI_Controller {

    function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

            $this->form_validation->set_rules('name', 'Imie', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('surname', 'Nazwisko', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); 
            $this->form_validation->set_rules('number', 'Numer telefonu', 'required|alpha_numeric|max_length[10]'); 
            $this->form_validation->set_rules('brand', 'Marka', 'required|alpha'); 
            $this->form_validation->set_rules('model', 'Model', 'required|alpha'); 
            $this->form_validation->set_rules('year', 'Rok produkcji', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('km', 'Ilosc KM', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('licenceseplate', 'Tablica rejestracyjna', 'required|max_length[15]'); 
            $this->form_validation->set_rules('description', 'Opis', 'required|max_length[300]'); 
            $this->form_validation->set_rules('city', 'Miasto', 'required|max_length[30]'); 

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');

        }
        else
        {
            $this->load->view('formsuccess');
        }

    }


}
?>

我的看法

    <html>
<head>
<title>My Form</title>
</head>
<body>


<?php echo form_open('form'); ?>

<h5>Wpisz swoje imię</h5>
<?php echo form_error('name'); ?>
<input type="text" name="name" value="<?php echo set_value('name'); ?>" size="50" />

<h5>Nazwisko</h5>
<?php echo form_error('surname'); ?>
<input type="text" name="surname" value="<?php echo set_value('surname'); ?>" size="50" />

<h5>Email Address</h5>
<?php echo form_error('email'); ?>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />

<h5>Numer telefonu</h5>
<?php echo form_error('number'); ?>
<input type="text" name="number" value="<?php echo set_value('number'); ?>" size="50" />

<h5>Marka</h5>
<?php echo form_error('brand'); ?>
<input type="text" name="brand" value="<?php echo set_value('brand'); ?>" size="50" />

<h5>Model</h5>
<?php echo form_error('model'); ?>
<input type="text" name="model" value="<?php echo set_value('model'); ?>" size="50" />

<h5>Rok produkcji</h5>
<?php echo form_error('year'); ?>
<input type="text" name="year" value="<?php echo set_value('year'); ?>" size="50" />


<h5>km</h5>
<?php echo form_error('km'); ?>
<input type="text" name="km" value="<?php echo set_value('km'); ?>" size="50" />



<h5>Rejestracja </h5>
<?php echo form_error('licenceseplate'); ?>
<input type="text" name="licenceseplate" value="<?php echo set_value('licenceseplate'); ?>" size="50" />

<h5>Opis </h5>
<?php echo form_error('description'); ?>
<input type="text" name="description" value="<?php echo set_value('description'); ?>" size="50" />

<h5>Miasto </h5>
<?php echo form_error('city'); ?>
<input type="text" name="city" value="<?php echo set_value('city'); ?>" size="50" />



<div><input type="submit" value="Submit" /></div>

</form>

</body>
</html>

我的表格
Wpisz swoje imię

您必须将数据发送到模型

在那里,您可以使用活动记录或普通查询来保存数据

必须注意的是,您需要将模型包括在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }
$this->load->model('Your model name')这应该包括在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }

$this->yourmodelname->functioninmodel
这是对模型的控制器函数调用

您必须将数据发送到模型

在那里,您可以使用活动记录或普通查询来保存数据

必须注意的是,您需要将模型包括在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }
$this->load->model('Your model name')这应该包括在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }

$this->yourmodelname->functioninmodel
这是对模型的控制器函数调用

在表单验证之后,您可以保存数据

在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }
您的_model.php

 public function save($data) {
   $this->db->set($data);
   $this->db->insert(table name here);
   $this->db->insert_id();
 }

表单验证后,您可以保存数据

在控制器中

    if ($this->form_validation->run() == FALSE){
        $this->load->view('myform');
    }
    else {
     $this->your_model->save($data);           
    }
您的_model.php

 public function save($data) {
   $this->db->set($data);
   $this->db->insert(table name here);
   $this->db->insert_id();
 }
嗯 我的观点是这样的:

    <?php

class Form extends CI_Controller {

    function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

            $this->form_validation->set_rules('name', 'Imie', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('surname', 'Nazwisko', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); 
            $this->form_validation->set_rules('number', 'Numer telefonu', 'required|alpha_numeric|max_length[10]'); 
            $this->form_validation->set_rules('brand', 'Marka', 'required|alpha'); 
            $this->form_validation->set_rules('model', 'Model', 'required|alpha'); 
            $this->form_validation->set_rules('year', 'Rok produkcji', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('km', 'Ilosc KM', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('licenceseplate', 'Tablica rejestracyjna', 'required|max_length[15]'); 
            $this->form_validation->set_rules('description', 'Opis', 'required|max_length[300]'); 
            $this->form_validation->set_rules('city', 'Miasto', 'required|max_length[30]'); 

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');

        }
        else
        {
            /*$this->load->view('formsuccess');*/
            $this->load->model ( 'form' );
            $this->form->save($data);
        }

    }


}
?>
数据库名称表单中的表

我不知道你想要什么好的 我的观点是这样的:

    <?php

class Form extends CI_Controller {

    function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

            $this->form_validation->set_rules('name', 'Imie', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('surname', 'Nazwisko', 'required|min_length[5]|max_length[25]|required|alpha'); 
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); 
            $this->form_validation->set_rules('number', 'Numer telefonu', 'required|alpha_numeric|max_length[10]'); 
            $this->form_validation->set_rules('brand', 'Marka', 'required|alpha'); 
            $this->form_validation->set_rules('model', 'Model', 'required|alpha'); 
            $this->form_validation->set_rules('year', 'Rok produkcji', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('km', 'Ilosc KM', 'required|alpha_numeric|max_length[5]'); 
            $this->form_validation->set_rules('licenceseplate', 'Tablica rejestracyjna', 'required|max_length[15]'); 
            $this->form_validation->set_rules('description', 'Opis', 'required|max_length[300]'); 
            $this->form_validation->set_rules('city', 'Miasto', 'required|max_length[30]'); 

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');

        }
        else
        {
            /*$this->load->view('formsuccess');*/
            $this->load->model ( 'form' );
            $this->form->save($data);
        }

    }


}
?>
数据库名称表单中的表


我不知道你想要什么样的

请给我一个它应该是什么样子的例子。Kombinował已经有了模型,但我无法得到效果。请给我一个它应该是什么样子的例子。Kombinował已经有了模型,但我无法得到效果。您可以在CI的《优秀用户指南》中找到与数据库类相关的所有信息。它很容易使用。请原谅我的英语:)您可以在CI的《优秀用户指南》中找到所有与数据库类相关的信息。它很容易使用。请原谅我的英语:)