Welcome Guest, Not a member yet? Register   Sign In
please hepl me.. about database..
#2

[eluser]Jelmer[/eluser]
First off, a couple of tips about using the forums:
- use the [code ] tag around your code snippets, this makes them a lot more readable.
- give the error you are receiving, most users won't completely re-enact your problem on their own server but can (from experience) deduce what causes the error

You say you have a problem connecting to the database, are you actually receiving an error that says so? Because when I look at your controller I see a couple of other problems:
- In your index() you load your view before loading helpers & model, so the helpers and model won't be available when your view is generated (that would cause problems)
- The same index() function isn't closed by a }, though there's an extra } after the addclient() function which would probably crash your controller as the index() function encapsulates your addclient() function
- This isn't the real problem, but it is somewhat bad form: you have a model written for DB insertion but you're putting it straight into the DB from your controller's addclient() function

Your controller might work better if you'd rewrite it to the following (I've added comments where I've edited code):
EDIT 20/2: correction to the model loading.
Code:
<?php

class Welcome extends Controller {

  function Welcome()
  {
      parent::Controller();
  }
  function index()
  {
      // removed the model as you don't use it in your view
      $this->load->helper(‘file’,‘form’,‘url’);
      $this->load->view(‘welcome_message’);
  }

  function addclient($client_data)
  {
      $this->load->model(‘Welcome_model’);
      $client_data = array(
           ‘client_id’ => $this->input->post(‘client_id’),
           ‘title’ => $this->input->post(‘title’),
           ‘name’ => $this->input->post(‘name’),
           ‘comments’ => $this->input->post(‘comments’),
      );
      $this->Welcome_model->addclient($client_data);
   }

// Removed the extra }

}

// Removed the PHP closing tag, not neccessary


Messages In This Thread
please hepl me.. about database.. - by El Forum - 02-19-2009, 04:25 AM
please hepl me.. about database.. - by El Forum - 02-19-2009, 05:29 AM
please hepl me.. about database.. - by El Forum - 02-19-2009, 05:30 AM
please hepl me.. about database.. - by El Forum - 02-19-2009, 08:56 PM
please hepl me.. about database.. - by El Forum - 02-19-2009, 11:41 PM
please hepl me.. about database.. - by El Forum - 02-20-2009, 05:31 AM
please hepl me.. about database.. - by El Forum - 02-20-2009, 07:28 AM
please hepl me.. about database.. - by El Forum - 02-23-2009, 08:03 PM
please hepl me.. about database.. - by El Forum - 02-24-2009, 05:01 PM
please hepl me.. about database.. - by El Forum - 02-24-2009, 06:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB