How to get the value of a switch and paste it into a database in a code igniter?

I have a form called feedback.php with two questions. I want to undo the value of the selected switch and paste it into the database in the code igniter. The name of the table is the “feedback” where I store these values. the html code for the form is here

<form role="form" method="post" name ="your_form" action="<?php echo base_url();?>/index.php/feedback_model/index" >
           <span class="badge">1</span></a> Is your complain solved ?  
          <div class="form-group">
            <div class="radio">
          <label><input type="radio" name="Question1"          
value="yes">Yes</label>
            </div>
            <div class="radio">
              <label><input type="radio" name="Question1" value="no">NO</label>
            </div>
        </div>  


         <span class="badge">2</span></a> How easy was it to complain to us?  
          <div class="form-group">
            <div class="radio">
              <label><input type="radio" name="Question2" value='excellent'>Excellent</label>
            </div>
            <div class="radio">
                <label><input type="radio" name="Question2" value="good">Good </label>
            </div>
            <div class="radio">
                <label><input type="radio" name="Question2" value="bad">Bad</label>
            </div>
            <div class="radio">
              <label><input type="radio" name="Question2" value="verybad">Very Bad</label>
            </div>
        </div>  
    </form>

In the controller, I have feedback.php with this code

 <?php
class feedback_model extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('feedback_model');
}
function index()
{
// Including Validation Library



// Setting Values For Tabel Columns
$data = array(
'complain_id' => $this->input->post('complain_id'),
'email' => $this->input->post('email'),
'response1' => $this->input->post('Qustion1'),
 'response1' => $this->input->post('Question2'),
 'response1' => $this->input->post('Question3'),
 'response1' => $this->input->post('Question4')

);
// Transfering Data To Model
$this->insert_model->form_insert($data);
// Loading View
$this->load->view('feedback');
}
}
?>

And in the model, I have feedback_model.php with this code.

<?php
class feedback_model extends CI_Model{
function __construct() {
parent::__construct();
}
function form_insert($data){
// Inserting in Table(feedback) of Database(college)
$this->db->insert('feedback', $data);
}
}
?>
+4
source share
2 answers

I created the same as yours

First you need to set up the project correctly. How to connect to the database, CI helpers

Here is my feedback.php controller

<?php

class feedback extends CI_Controller {

    function __construct() {

        parent::__construct();

        $this->load->model('feedback_model');
    }

    function index() {

        // Loading View
        $this->load->view('feedback');
    }

    function submit() {

        // check for method
        if ($this->input->post('REQUEST_METHOD') == 'POST') {

            // Including Validation Library
            // Setting Values For Tabel Columns
            $data = array(
                'response1' => $this->input->post('Qustion1'),
                'response2' => $this->input->post('Question2')
            );

            // Transfering Data To Model
            $this->feedback_model->form_insert($data);
        }


    }
}

Here are my feedback_model.php messages really changing with yours

<?php

class feedback_model extends CI_Model{

    function form_insert($data){
        // Inserting in Table(feedback) of Database(college)
        $this->db->insert('feedback', $data);
    }
}

, feedback.php

<html>
  <head>
    <title></title>
  </head>
  <body>
    <form role="form" method="POST" action="feedback/submit">
      <span class="badge">1</span></a> Is your complain solved ?
      <div class="form-group">
        <div class="radio">
          <label><input type="radio" name="Question1"
          value="yes">Yes</label>
        </div>
        <div class="radio">
          <label><input type="radio" name="Question1" value="no">NO</label>
        </div>
      </div>
      <span class="badge">2</span></a> How easy was it to complain to us?
      <div class="form-group">
        <div class="radio">
          <label><input type="radio" name="Question2" value='excellent'>Excellent</label>
        </div>
        <div class="radio">
          <label><input type="radio" name="Question2" value="good">Good </label>
        </div>
        <div class="radio">
          <label><input type="radio" name="Question2" value="bad">Bad</label>
        </div>
        <div class="radio">
          <label><input type="radio" name="Question2" value="verybad">Very Bad</label>
        </div>
      </div>
      <div class="form-group">
        <input type="submit" value="submit" name="submit">
      </div>
    </form>
  </body>
</html>

method = "POST" action = "feedback/submit"

, , - uri, .

,

i , post

,

1

2

feedback_model

$data = array(
    'response1' => $this->input->post('Qustion1'),
    'response2' => $this->input->post('Question2')
);

// Transfering Data To Model
$this->feedback_model->form_insert($data);

.

- MVC

feedback_model.php, feedback_model.php , .

,

+3

, , action

 <form role="form" method="post" name ="your_form" action="<?php echo base_url(); ?>/index.php/feedback_model/index" >

function index()
{
// Setting Values For Table Columns
$data = array(
'complain_id' => $this->input->post('complain_id'),
'email' => $this->input->post('email'),
'response1' => $this->input->post('Qustion2'),// you radio button data
'response2' => $this->input->post('Qustion1'),
);
// Transfering Data To Model
$this->insert_model->form_insert($data);
// Loading View
$this->load->view('feedback',$data);

}

,

$this->input->post('Question2')
$this->input->post('Question3')
+1

All Articles