CodeTalk
CodeTalk

Reputation: 3667

Submitting basic input to database Codeigniter

So, all I'm trying to do is submit a few values to a database from form input.

I have a controller clientcreation.php:

<?php

class Clientcreation extends CI_Controller
{
  function index(){
     $this->load->view('files/header',$clientRegistration);
     $this->load->view('files/navigation');
     $this->load->view('pages/clientcreation');
     $this->load->view('files/footer');

    ## validation rules here working fine.

     $this->form_validation->set_rules($RegistrationRequiredFields);
        ## Perform Validation
        if ($this->form_validation->run() == FALSE){
             echo validation_errors();             ## show the errorneous fields
        }

    else{
            #### load :: models
            $this->load->model('pages/clientcreationmodel','',TRUE);
                ## get [hashed] inputted pass and submit.
                $this->Clientcreationmodel->hashed_client_pass_and_submit();
            # then, load success page:
            $this->load->view('pages/success/clientRegistrationSuccess');
    }



  }

}

a model clientcreationmodel.php:

<?php
class Clientcreationmodel extends CI_Model{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function hashed_client_pass_and_submit(){
        ## create hashed version of client inputted [pass]
    /*    
        $initialVal = $_POST['pass'];
        $HashedPassVal = hash('sha512', $initialVal);
        $SaltValue = mcrypt_create_iv(10, MCRYPT_DEV_URANDOM);
        $finalHashedValue = $HashedPassVal.$SaltValue;
    */    
        ## process and insert into db
        $this->input->post('email', TRUE);     
        $this->input->post('pass', TRUE);
        $this->input->post('fname', TRUE);
        $this->input->post('lname', TRUE);
        $this->input->post('title', TRUE);
        $this->input->post('co', TRUE);
        $this->input->post('phone', TRUE);
        $this->input->post('state', TRUE);  
        $this->input->post('numapps', TRUE);
        $this->input->post('versCntrl', TRUE);
        $this->input->post('testFreq', TRUE);
        $this->input->post('submit');

        $this->db->insert('client', $this);
   }

}
?>

a view clientcreation.php:

<?php
    echo form_open('index/pages/clientcreation',$CustCreationFormAttr);
    echo form_label('Email: ','email');
        echo form_input($CustCreationEmail);echo '<br>';
    echo form_label('Password: ', 'pass');echo '<br>';
        echo form_password($CustCreationPassword);echo '<br>';
    echo form_label('Password Confirm: ', 'passConf');echo '<br>';
        echo form_password($CustCreationConfPassword);echo '<br>';
    echo form_label('First Name: ','fname');echo '<br>';
            echo form_input($CustCreationFirstName);echo '<br>';
    echo form_label('Last Name: ','lname');echo '<br>';
            echo form_input($CustCreationLastName);echo '<br>';
    echo form_label('Title: ', 'title');echo '<br>';
            echo form_input($CustCreationClientTitle);echo '<br>';
    echo form_label('Company: ', 'co');echo '<br>';
            echo form_input($CustCreationCompany);echo '<br>';
        echo form_label('Phone: ','phone');echo '<br>';
            echo form_input($CustCreationPhone);echo '<br>';
    echo form_label('State: ','state');echo '<br>';
            echo form_dropdown('states',$CustCreationState,'Alabama');echo '<br>';
    echo form_label('Number of Applications: ','numapps');echo '<br>';
            echo form_input($CustCreationNumApps);echo '<br>';
    echo form_label('Version Control: ','versCntrl');echo '<br>';
            echo form_dropdown('versCntrl',$CustCreationVerCntrl,'Subversion'); echo '<br>';
    echo form_label('How often do you test? ','testFreq');echo '<br>';
            echo form_dropdown('freq',$CustCreationTestFreq,'Daily');echo '<br>';
    echo form_submit($CustCreationSubmit,'Submit');    
?> 

but after i submit I get the following error: img2

Is it throwing this error because the file clientcreationmodel.php isnt the same naming convention of clientcreation.php as with the view and controller ?

If I try to modify the model class in the model as class Classcreation extends CI_Model{} it throws the error: Fatal error: Cannot redeclare class Clientcreation . What should I do here?

Upvotes: 1

Views: 401

Answers (1)

Rooster
Rooster

Reputation: 10077

once you load your model, you will spell the instance with a lowercase c

so in your controller, it would be

$this->clientcreationmodel->hashed_client_pass_and_submit();

notice its lowercase now.

also, the loader for the models second parameter shouldn't be '' and you don't need to set the 3rd parameter at all. You can do this and it should work fine. The second parameter is used to set a different object name than default. So this should work fine.

$this->load->model('pages/clientcreationmodel');

Upvotes: 1

Related Questions