Welcome Guest, Not a member yet? Register   Sign In
cann't insert for database...
#1

[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>&lt;input type="text" name="title" id="title" size="40" maxlength="30" /&gt;&lt;/td>
</tr>
<tr>
<td valign="top"> Name: </td>
<td>&lt;input type="text" name="name" id="name" size="40" maxlength="30" /&gt;&lt;/td>
</tr>
<tr>
<td valign="top"> Comments: </td>
<td>&lt;input type name="comments" id="comments" size="40" maxlength="30" /&gt;&lt;/td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&lt;input type="submit" name="form_feedback" id="form_feedback" value="submit" /&gt;&lt;/td>
</tr>
</table>
&lt;/form&gt;
<br/>




Controller

&lt;?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);

}
}
}


/?&gt;
#2

[eluser]Relexx[/eluser]
have you included 'database' to you autoload libraries? or add
Code:
$this->load->database();
to your model.

Have you set you config/database.php file correctly
http://ellislab.com/codeigniter/user-gui...ation.html
#3

[eluser]pistolPete[/eluser]
[quote author="fyzza" date="1234954626"]i have problem to insert data in database.[/quote]
What's the error message you get?
#4

[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.
#5

[eluser]fyzza[/eluser]
[quote author="Relexx" date="1234956085"]have you included 'database' to you autoload libraries? or add
Code:
$this->load->database();
to your model.

Have you set you config/database.php file correctly
http://ellislab.com/codeigniter/user-gui...ation.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";
#6

[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?
#7

[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);
#8

[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!
#9

[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..
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB