cann't insert for database... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: cann't insert for database... (/showthread.php?tid=15889) Pages:
1
2
|
cann't insert for database... - El Forum - 02-17-2009 [eluser]fyzza[/eluser] Hi.. i have problem to insert data in database.. can you help me? Here are their coding for model, view and controller? What is the problem? can you help me, please? Model <?php class Welcome_model extends Model { function welcome_model() { parent::Model(); } function adddata($data) { $this->db->insert('title','name','comments', $data); $data = array( 'title' => $this->input->post('title'), 'name' => $this->input->post('name'), 'comments' => $this->input->post('comments') ); $newtit = $this->input->post('title'); $newtname = $this->input->post('name'); $newcomm = $this->input->post('comments'); return TRUE; } } ?> View <?php $attributes = array ('class'=>'welcome_message', 'id'=>'form_feedback'); echo form_open('welcome_message', $attributes);?> <table> <tr> <td valign="top"> Title: </td> <td><input type="text" name="title" id="title" size="40" maxlength="30" /></td> </tr> <tr> <td valign="top"> Name: </td> <td><input type="text" name="name" id="name" size="40" maxlength="30" /></td> </tr> <tr> <td valign="top"> Comments: </td> <td><input type name="comments" id="comments" size="40" maxlength="30" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="form_feedback" id="form_feedback" value="submit" /></td> </tr> </table> </form> <br/> Controller <?php class Welcome extends Controller { function index() { $this->load->model('welcome_model'); $this->load->view('welcome_message'); function welcome() { $data['form_feedback'] = $this->input->post('form_feedback'); $newtit = $this->input->post('title'); $newtname = $this->input->post('name'); $newcomm = $this->input->post('comments'); $data = array( 'title' => $this->input->post('title'), 'name' => $this->input->post('name'), 'comments' => $this->input->post('comments') ); $this->db->insert('feedback', $data); } } } /?> cann't insert for database... - El Forum - 02-17-2009 [eluser]Relexx[/eluser] have you included 'database' to you autoload libraries? or add Code: $this->load->database(); Have you set you config/database.php file correctly http://ellislab.com/codeigniter/user-guide/database/configuration.html cann't insert for database... - El Forum - 02-18-2009 [eluser]pistolPete[/eluser] [quote author="fyzza" date="1234954626"]i have problem to insert data in database.[/quote] What's the error message you get? cann't insert for database... - El Forum - 02-18-2009 [eluser]fyzza[/eluser] [quote author="pistolPete" date="1234961679"][quote author="fyzza" date="1234954626"]i have problem to insert data in database.[/quote] What's the error message you get?[/quote] 404 Page Not Found The page you requested was not found. cann't insert for database... - El Forum - 02-18-2009 [eluser]fyzza[/eluser] [quote author="Relexx" date="1234956085"]have you included 'database' to you autoload libraries? or add Code: $this->load->database(); Have you set you config/database.php file correctly http://ellislab.com/codeigniter/user-guide/database/configuration.html[/quote] yes, this is my autoload. $autoload['libraries'] = array('database', 'site_sentry', 'session'); this is my database $active_group = "default"; $db['default']['hostname'] = "localhost"; $db['default']['username'] = ""; $db['default']['password'] = ""; $db['default']['database'] = "feedback"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = FALSE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; cann't insert for database... - El Forum - 02-18-2009 [eluser]pistolPete[/eluser] That error message is not related to a database issue! How are you accessing your controller? Do you have any custom routes? Did you setup a .htaccess file? cann't insert for database... - El Forum - 02-18-2009 [eluser]fyzza[/eluser] [quote author="pistolPete" date="1234963313"]That error message is not related to a database issue! How are you accessing your controller? Do you have any custom routes? Did you setup a .htaccess file?[/quote] i didn't use htaccess file.. i use mysql.. $this->db->insert( $data); cann't insert for database... - El Forum - 02-18-2009 [eluser]pistolPete[/eluser] You have apparently no idea what you are doing... You mix up .htaccess with mysql, you have a model but aren't using it, instead you do the database stuff in you controller. I suggest having a look at the video tutorials and the user guide! cann't insert for database... - El Forum - 02-18-2009 [eluser]fyzza[/eluser] [quote author="pistolPete" date="1234964130"]You have apparently no idea what you are doing... You mix up .htaccess with mysql, you have a model but aren't using it, instead you do the database stuff in you controller. I suggest having a look at the video tutorials and the user guide![/quote] ok, thank you.. i try my best.. but if i have problem any more, i hope you can help me again.. thank.. cann't insert for database... - El Forum - 02-18-2009 [eluser]Relexx[/eluser] [quote author="fyzza" date="1234963229"] $db['default']['username'] = ""; $db['default']['password'] = ""; $db['default']['database'] = "feedback"; $db['default']['dbdriver'] = "mysql"; [/quote] My MySQL is not the best, I have an Oracle background. But you seem to have no username. Does this mean that you are assuming to log in as root? |