parse error in controller file

2020-05-06 17:00发布

问题:

i made a controller name of user.php i test complete project on local host it works fine but when i upload online on website it shows error , i submit the form then form load controller called user.php and error on the first line its called parse error i check but still the same will you please suggest.

<?php 

class User extends CI_Controller {

                function __construct()
                {
                parent::__construct();
                $this->load->helper('form');
                $this->load->helper('url');
                }

public function create_user()
            {
            // field name, error message, validation rules
            $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_signup');
            }
            else
            {           
            $this->load->model('Users_model');
            if($this->input->post("language")=="ar")
            {
            $this->load->view('ar_thanks');
            }
            else
            {
            $this->load->view('en_thanks');
            }
            if($query = $this->Users_model->create_member())
            {
            $this->load->view('ar_thanks');         
            }
                }               
                        }

    }   

回答1:

Please format your code and use IDE. And you will not have these errors. Your formatted code:

<?php
class User extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
    }

    public function create_user()
    {
        // field name, error message, validation rules
        $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_signup');
        } else {
            $this->load->model('Users_model');
            if($this->input->post("language")=="ar") {
                $this->load->view('ar_thanks');
            } else {
                $this->load->view('en_thanks');
            }
            if($query = $this->Users_model->create_member()) {
                $this->load->view('ar_thanks');
            }
        }
    }
}