Welcome Guest, Not a member yet? Register   Sign In
form post not working
#1

[eluser]brian-[/eluser]
I tried to follow the 20 minute video. I created the form along with the function to accept the post values. Unfortunately that didn't work for me.

I did take the same form I created and created a test php file to get the post values, and they work.

So what am I doing wrong? Here is my code:

<?=form_open('test/adding_review');?>
Name
<br />
&lt;input name="aname" type="text" value="" /&gt;
<br />
Review
<br />
&lt;textarea name="info" rows="10"&gt;&lt;/textarea>
<br />
&lt;input type="submit" value="Submit Review" /&gt;
&lt;/form&gt;


_______________________________________________________________________


function adding_review(){
$data = array(
'revw_name' => $this->input->post('aname'),
'revw_text' => $this->input->post('info') );

$this->db->set($data);
$this->db->insert('Reviews');

}


__________________________________________________________

Maybe a configuration setting? I have no idea...The values added to the database are 0 0.
#2

[eluser]mi6crazyheart[/eluser]
Try this:

Code:
function adding_review()
{
$revw_name = $this->input->post(‘aname’);
$revw_text = $this->input->post(‘info’) ;

$this->db->set('DB_table_filed_name', $revw_name); // DB_table_filed_name = respective DB table  filed name where value need to be store
$this->db->set('DB_table_filed_name', $revw_text); //
$this->db->insert(‘Reviews’);

  }
#3

[eluser]brian-[/eluser]
Thanks for the response. It did input the same information into the database. Values of 0 0. So maybe there is something wrong with the form?

The issue seems to be a post issue. I have tried with echos, and the page is blank. When it is inserted into the database, both have a value of 0.
#4

[eluser]mi6crazyheart[/eluser]
Can u show the HTML code of u'r that VIEW file... ? Check also, the control is coming to the respective controller function after u'r u click on submit button.
#5

[eluser]Greg Aker[/eluser]
@brian-, if you copied code directly from @mi6crazyheart's post, note that there are some 'curly quotes' in it. Looks over all of the quotes in the example to make sure they are:

Code:
'
and not:
Code:

As that could be the source of errors if you did a direct code copy.

-greg

ETA: var_dump($_POST); exit; right after submission to see what's going on as well.
#6

[eluser]brian-[/eluser]
I tried a "re-install" of codeigniter, and got the same results..So I have changed some of the tags.

Below is my view file.
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Order&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php foreach($query->result() as $row): ?&gt;

Name
<br />
&lt;?=$row->revw_name?&gt;
<br />
Review
<br />
&lt;?=$row->revw_text?&gt;
&lt;?php endforeach; ?&gt;

<br />
&lt;?=form_open('order/process');?&gt;
Name
<br />
&lt;input type="text" name="revw_name" /&gt;
<br />
Review
<br />
&lt;textarea name="revw_text" rows="10"&gt;&lt;/textarea>
<br />
&lt;input type="submit" value="Submit" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

When I hit submit, it does go to the correct controller function since I did a simple echo command.

Here is the code of my controller file
Code:
class Order extends Controller {

    function Order()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index()
    {
        $data['query'] = $this->db->get('Reviews');
        $this->load->view('order_process', $data);
    }
    
    function process()
    {    
        $revw_name = $this->input->post('revw_name');
$revw_text = $this->input->post('revw_text') ;

$this->db->set('revw_name', $revw_name); // DB_table_filed_name = respective DB table  filed name where value need to be store
$this->db->set('revw_text', $revw_text); //
$this->db->insert('Reviews');
        
        
}
}

And the post information placed into the database is 0 0. (I have two rows)
#7

[eluser]Greg Aker[/eluser]
change your process function to:

Code:
function process()
    {
        echo '<h1>$this->input->post()</h1>';
        echo '<pre>'; print_r($this->input->post('revw_name'),
                              $this->input->post('revw_text'));
        echo '</pre>';

        echo '<h1>$_POST</h1>';
        echo '<pre>'; print_r($_POST); exit; echo '</pre>';
        exit;
    }

what does it output?
#8

[eluser]mi6crazyheart[/eluser]
Is any new record is creating in u'r DB table with value inserting value 0,0 after clicking submit button of u'r form... ? Also check, whether those post values are coming to u'r controller function as "Greg Aker" said...
#9

[eluser]brian-[/eluser]
Yes, new records are being created in my database.

@Greg here is the output:

$this->input->post()

$_POST

Array
(
)
#10

[eluser]mi6crazyheart[/eluser]
@brian-

Go to u'r form page. Right click on browser. Click, show source code. Copy that source code & paste at here. Let's see what's the actual HTML code are generating at there...




Theme © iAndrew 2016 - Forum software by © MyBB