Welcome Guest, Not a member yet? Register   Sign In
Controller Insert data
#1

[eluser]ann91[/eluser]
Hello everyone, I have difficulties about this code.

whether this Controller is correct or not???
Code:
function input(){
    
      if ($this->input->post(submit))
        {
          $this->formmodel->insert()
        }
      else
        {
          $this->load->view('Myform');
        }

but, this is the model..

Code:
<?php

class Formmodel extends CI_Model{
  
  function __construct(){
    parent::__construct();
  
  }
  
  function insert($username, $password, $confpass, $email){
    $data = array(
    "username" => $this->input->post('username'),
    "password" => $this->input->post('password'),
    "confpass" => $this->input->post('confpass'),
    "email"    => $this->input->post('email')
    );
    
  $this->db->insert('cust',$data);
  }
}
?>

Can you fix it...
Confusedmirk:
#2

[eluser]InsiteFX[/eluser]
ann91,

Did you autoload your model? If not then you need to load your model in your controller.
Also use single qoutes on your array field names.

It would also help if you show your form code.

InsiteFX
#3

[eluser]ann91[/eluser]
sorry this is a correct code..

i had load it, but the notice is "Use of undefined constant submit - assumed 'submit'"

Code:
if($this->form_validation->run()){
    
      if ($this->input->post(submit))
        {
          $this->load->view('formsuccess');  
        }
      else
        {
          $this->load->view('MyForm');
        }
      
    }
    else
      {
          $this->load->view('Myform');
      }
#4

[eluser]InsiteFX[/eluser]
Try this ann91.
Code:
if($this->form_validation->run() == FALSE)
{
    $this->load->view('MyForm');
}
else
{
    $this->load->view('formsuccess');
}

InsiteFX
#5

[eluser]ann91[/eluser]
that's not what I meant,
my form_validation has succeeded, about this
Code:
if ($this->input->post(submit))
        {
          $this->load->view('formsuccess');  
        }
correct or not??
the data not entered into the database yet..
#6

[eluser]InsiteFX[/eluser]
Did you load your model and database?

You do not need to check the submit!

InsiteFX
#7

[eluser]ann91[/eluser]
yes, i had load it..
#8

[eluser]InsiteFX[/eluser]
Let me explain this a little better for you, when you click on the submit button it passes back TRUE to the form_validation so it then carries out the else formseccess. If it is FALSE the it will load MyForm.
Code:
if($this->form_validation->run() == FALSE)
{
    $this->load->view('MyForm');
}
else
{
    $this->load->view('formsuccess');
}

No need to check for the submit button, use the code I showed you.

I also need to see your form code for your views.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB