Welcome Guest, Not a member yet? Register   Sign In
not writing to database
#1

[eluser]diasansley[/eluser]
i have a simple controller to sumbmit the data to a database and get it back.
but the data is not writing to the database.

can some1 help me with a workaround.


Thnaks
#2

[eluser]tonanbarbarian[/eluser]
help us to help you
provide some detail
#3

[eluser]InsiteFX[/eluser]
Show your code for your controller and model!

InsiteFX
#4

[eluser]diasansley[/eluser]
ok ill paste my codes here

this is the controller file form.php
<?php
class Form extends Controller {
function Form(){
parent::Controller();
$this->load->model('form_model');
$this->load->database();
$this->load->helper(array('form','url'));
}
function index() {
$data['title']='Form Data';
$data['result'] = $this->form_model->get_all_data();
$this->load->view('forms_view',$data);
}
function submit() {
$this->form_model->submit_posted_data();
redirect('form');
}
}
?>


this is the view file forms_view.php
<html>
<head>
<title><?=$title;?></title>
</head>
<body>
<h1>&lt;?=$title;?&gt;</h1>
<table border='1'>
<tr>
<th>Title</th>
<td>Entry</td>
</tr>
&lt;?php foreach($result->result_array() as $entry):?&gt;
<tr>
<th>&lt;?=$entry['title'];?&gt;</th>
<td>&lt;?=$entry['body'];?&gt;</td>
</tr>
&lt;?php endforeach;?&gt;
</table>
&lt;?php echo form_open('form/submit'); ?&gt;
<br><br>
Titile<br>
&lt;input type="text" name="Title"&gt;&lt;br>
Entry<br>
&lt;input type="text" name="data"&gt;
&lt;input type="submit" value="New"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


this is the model form_model.php
&lt;?php
class Form_model extends Model {
function Formmodel() {

parent::Model();
}
function submit_posted_data() {
$this->db->insert('form',$_POST);
}
function get_all_data() {
$data['result']=$this->db->get('form');
return $data['result'];
}
}
?&gt;
#5

[eluser]tonanbarbarian[/eluser]
in your controller change the following:

Code:
function submit() {
$this->form_model->submit_posted_data();
echo $this->db->last_query();
}

this will show you what the last query ran was.
from that you might be able to determine the issue.

personally i would NEVER do
Code:
$this->db->insert(‘form’,$_POST);
because you have no idea what data could be submitted
you would really be better off doing something like this
Code:
function submit_posted_data() {
$data = array(
'title'=>$this->input->post('Title', TRUE),
'data'=>$this->input->post('data',TRUE),
);
$this->db->insert(‘form’,$data);  
}

If your config is setup to filter all post i.e. $config['global_xss_filtering'] = TRUE; then it is reasonably safe to use $_POST, but I prefer to get out of the habit of using it and use the input library instead.
#6

[eluser]diasansley[/eluser]
the url
http://example.com/index.php/form/submit


and it generated the foll error
The requested URL /index.php/form/submit was not found on this server.


im new to codeIgniter so please dnt mind if its a not so relevant question.


Thanks
#7

[eluser]diasansley[/eluser]
i am still tryin to find a solution for the same



Please a solution
thanks




Theme © iAndrew 2016 - Forum software by © MyBB