codeigniter - 表单提交错误

时间:2014-01-07 12:07:34

标签: php forms codeigniter

我做了一个正常的表格,用户提交数据名称,电子邮件和城市形式的这项工作,我使用一些编码,我仍然不知道我错在哪里请建议。

路由

$route['default_controller'] = "welcome";
控制器中的

welcome.php

public function index()
    {
        $this->load->view('ar_signup');     
        $this->load->helper('url');
    }
}

视图中的表单的ar_signup

<!DOCTYPE html> 
<html lang="en-US">
  <head>
    <title>Landing Page</title>
    <meta charset="utf-8">
    <link href="assests/css/ar/ar.css" rel="stylesheet" type="text/css">
  </head>
  <body>
        <?php echo validation_errors(); ?>
        <?php echo form_open('user'); ?>
        <label for="name">Name:</label>
        <input type="name" id="name" name="name">   
        <label for="email">Email:</label>       
        <input type="email" id="email" name="email">        
        <label for="city">City:</label>     
        <input type="city" id="city" name="city">       
        <input type="submit" value="Login">     
        </div>      
        </form>     

  </body>
</html> 

控制器中的user.php

<?php
function create_member()
    {
        $this->load->library('form_validation');        

        // field name, error message, validation rules
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('city', 'City', 'trim|required');     

        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('ar_thanks');
        }
        else
        {           
            $this->load->model('users_model');

            if($query = $this->Users_model->create_member())
            {
                $this->load->view('ar_landing');            
            }

        }

    }

user_model.php在模型中提及

<?php
function create_member()
    {

        $this->db->where('user_name', $this->input->post('username'));
        $query = $this->db->get('users');

        if($query->num_rows > 0){           
        }else{
            $new_member_insert_data = array(
                'name' => $this->input->post('name'),
                'email' => $this->input->post('email'),
                'city' => $this->input->post('city'),                           
            );
            $insert = $this->db->insert('users', $new_member_insert_data);
            return $insert;
        }

    }//create_member
}

2 个答案:

答案 0 :(得分:0)

在您的user.php控制器更改

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

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

在您的视图文件中提供:<?php echo form_open('user/create_member'); ?>

现在点击你的: localhost / landingpage / index.php / user / create_member

答案 1 :(得分:0)

如果您的控制器是“欢迎”,那么您的网址应为“localhost / welcome”。还要检查你的mod_rewrite。 的修改

我认为这将是你的php安装,因为你说当你删除php代码时,它工作得很好。