Почему мой codeignitor не отправляется в базу данных? Это плохо связано? - PullRequest
0 голосов
/ 19 июня 2020

Ребята, я новичок в php и codeigniitor. Я пытаюсь создать приложение для отправки сообщений, но оно не работает, пожалуйста, помогите.

вот моя функция контроллера

public function status(){
        $this->load->library('form_validation');
        $this->form_validation->set_rules('post', 'Post Something', 'required');

    if ($this->form_validation->run() == FALSE) {
        $user = $this->session->userdata('user');
        $data1['user'] = $user;
        $this->load->view('pages/panel',$data1); 
        }
        else{
            $this->load->model('reg_model');
            $formArray1 = array(); 
            $formArray1['post'] = $this->input->post('post');
            $formArray1['posted_by'] = $user['ID'];
            $this->reg_model->create1($formArray);
            $this->session->set_flashdata('msg', 'Your account is created successfully');
            redirect(base_url().'index.php/Registration/panel');

        }

вот моя форма

<?php echo validation_errors();?>
            <form action = " <?php echo base_url()?>registration/status" name= "registrationForm1" id="registrationForm1" method = "post">
            <label class =" form-control" for="post">Post Something</label></br>
            <textarea style =" width:100%" class="form-control" rows="3" id="post" placeholder="Your message..."></textarea>
                  <p class ="invalid-feedback"><?php echo form_error('posts');?></p></br>
            <button type="submit" class="btn btn-primary btn-block">Post</button>
            </form>

моя модель:

public function create1($formArray1)
    {
       $this->db->insert('posts', $formArray1);
    }

1 Ответ

0 голосов
/ 19 июня 2020

Вы должны использовать $formArray1, а не $formArray

$formArray1 = array(); 
$formArray1['post'] = $this->input->post('post');
$formArray1['posted_by'] = $user['ID'];
$this->reg_model->create1($formArray1);

, а в модели: -

public function create1($formArray1)
    {
       $this->db->insert('users', $formArray1);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...