not writing to database |
[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
[eluser]InsiteFX[/eluser]
Show your code for your controller and model! InsiteFX
[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><?=$title;?></h1> <table border='1'> <tr> <th>Title</th> <td>Entry</td> </tr> <?php foreach($result->result_array() as $entry):?> <tr> <th><?=$entry['title'];?></th> <td><?=$entry['body'];?></td> </tr> <?php endforeach;?> </table> <?php echo form_open('form/submit'); ?> <br><br> Titile<br> <input type="text" name="Title"><br> Entry<br> <input type="text" name="data"> <input type="submit" value="New"> </form> </body> </html> this is the model form_model.php <?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']; } } ?>
[eluser]tonanbarbarian[/eluser]
in your controller change the following: Code: function submit() { 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); you would really be better off doing something like this Code: function submit_posted_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.
[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
[eluser]diasansley[/eluser]
i am still tryin to find a solution for the same Please a solution thanks |
Welcome Guest, Not a member yet? Register Sign In |