• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about submission form to database

#1
I'm pretty new at CodeIgniter. I'm now wanting to create my first submission form to my MySQL database. My database settings are correct in the database.php in the config folder. I know that I need a view page, a controller page and a model page for this task, but I need to see some samples that I can use and test.  I found some sample view, controller and model code on this page but I'm getting an error message on my test view page. Below is line 10 in the code. Any ideas what's happening? Or do you know any other places where I can copy the view, controller and model code to try to replicate this on my own site for practice?
PHP Code:
<?php echo form_open('insert_ctrl'); ?>
Reply

#2
I would recommend you going through the html form at first.

Like,

View : 

PHP Code:
<form action="POST" method="<?php echo base_url('/your_controller/lets_post_it');?>">
 
  <input type="text" name="member_name" class="blabla" placeholder="Please Insert Your Name"/>
 
  <input type="text" name="member_username" class="blabla" placeholder="Please Insert Your Username"/>

<
buttonSend it </button>

</
form


Controller 

PHP Code:
public function lets_post_it() {

 
 $name $this->input->post('member_name);  //first retrieve from inputs
  $username = $this->input->post('
member_username');

  $data = array(
     '
member_name'=> $name,  // then match with your database
     '
member_username' => $username
);

   $this->load->model('
My_Model');
  $result = $this->My_Model->upload_it($data);  // and send it to model

  if($result){
      $this->session->set_flashdata('
success', 'Data has been inserted successfully');
      redirect($SERVER['
HTTP_REFERER']);
}


MODEL

PHP Code:
public function upload_it($data){
 
 
   $query 
$this->db->insert('table_name'$data);

 
  return $query;

Reply

#3
You don't have the form helper loaded. Load it in your controller constructor.
Simpler is always better
Reply

#4
The error that "test view page" displays indicates you have not loaded the "form" helper.

The following line of code is in the example you are working from

PHP Code:
$this->load->library('form_validation'); 

It turns out that "form_validation" will load the "form" helper for you.

If you are not using "form_validation" in your test then explicitly load the "form" helper in your controller with this line.
PHP Code:
$this->load->helper('form'); 
Reply

#5
(08-07-2019, 03:30 PM)dave friend Wrote: The error that "test view page" displays indicates you have not loaded the "form" helper.

The following line of code is in the example you are working from

PHP Code:
$this->load->library('form_validation'); 

It turns out that "form_validation" will load the "form" helper for you.

If you are not using "form_validation" in your test then explicitly load the "form" helper in your controller with this line.
PHP Code:
$this->load->helper('form'); 
Thanks for the info.  Do I replace in my controller

PHP Code:
$this->load->library('form_validation'); 

with this below?
PHP Code:
$this->load->helper('form'); 
Reply

#6
(08-07-2019, 03:45 PM)ronniebel Wrote:
(08-07-2019, 03:30 PM)dave friend Wrote: The error that "test view page" displays indicates you have not loaded the "form" helper.

The following line of code is in the example you are working from

PHP Code:
$this->load->library('form_validation'); 

It turns out that "form_validation" will load the "form" helper for you.

If you are not using "form_validation" in your test then explicitly load the "form" helper in your controller with this line.
PHP Code:
$this->load->helper('form'); 
Thanks for the info.  Do I replace in my controller

PHP Code:
$this->load->library('form_validation'); 

with this below?
PHP Code:
$this->load->helper('form'); 

If you are not using field validation you can (but do not have to) replace library('form_validation') with helper('form'). One or the other must be used.
Reply

#7
You load helpers, libraries and models in the controller where you need them. If you need specific helpers, libraries or models in all your controllers, you can autoload them in application/config/autoload.php.
It's a good idea to autoload the url helper, for instance, and also the database library. If you use session variables all over your application, autoload the session library as well.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.