Welcome Guest, Not a member yet? Register   Sign In
Help - can't get POST form data
#1

[eluser]tjackson1982[/eluser]
Hello,

I have some simple files that I would think would capture the POST from a form but just doesn't seem to get the actual data.

Funny thing is it detects if IS data, but doesn't actually collect it - even using the $_POST['field']; method.

I do get a blank entry in my table.

Controller -

Code:
class Posting extends Controller {

    var $headline ='';

    function Posting()
    {
        parent::Controller();    
        $this->load->model('Headline','Posting',TRUE);
    }
    
    function index()
    {
        $this->load->view('posting_page.htm');
    }
    
    function posting_headline()
    {
        $headline = $_POST['headline'];
        
        if ( $this->input->post('headline') !== FALSE ) {
            $this->Posting->posting($headline);
        }
    
    }
}

Model

Code:
class Headline extends Model {

    var $headline ='';
    var $source ='';
    var $link ='';
    var $image_link='';
    var $author='';
    var $views='';
    var $catagory='';
    var $date_time='';
    

    function Headline()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function posting($headline_in) {
    
        $headline = $headline_in;//$this->input->post('headline', TRUE);
        $source = $this->input->post('source', TRUE);
        $link = $this->input->post('link', TRUE);
        $image_link = $this->input->post('img_link', TRUE);
        $author = $this->input->post('author', TRUE);
        $views = $this->input->post('view', TRUE);
        $catagory = $this->input->post('catagory', TRUE);
        
        $date_time=time();
        
        $this->db->insert('headline', $this);
    }


}

and View file.

Code:
<form method="post" name="posting_form" action="posting_headline/">
        
Headline title
<input name="headline" type="text">
Source
<input id="source" type="text">
Source Link
<input id="link" type="text">
Any Image links
<input id="img_link" type="text">
Who wrote it
<input id="author" type="text">
How many views (may not be an input)
<input id="view" type="text">
What Catagory
<input id="catagory" type="text">

<input type="submit" value="Submit">
</form>

It all seems logical
#2

[eluser]tjackson1982[/eluser]
Suffering from a double whammy -

Code:
function posting($headline_in) {
    
        $headline = $headline_in;//$this->input->post('headline', TRUE);
        $source = $this->input->post('source');
        $link = $this->input->post('link');
        $image_link = $this->input->post('img_link');
        $author = $this->input->post('author');
        $views = $this->input->post('view');
        $catagory = $this->input->post('catagory');
        
        $date_time=time();
        
        $data = array(
               'headline' => $headline,
               'source' => $source,
               'link' => $link,
               'image_link' => $image_link,
               'author' => $author,
               'catagory' => $catagory,
               'date_time' => $date_time
            );
        
$this->db->insert('headline', $data);

I changed my posting function to this, and the Headline gets in...

So that tells me sending $this to db->insert is false. and using the input in the model is false.

Hope this helps somebody - so far I tested it with IE.
#3

[eluser]tjackson1982[/eluser]
Still a puzzle,

made another change.

Code:
function posting_headline()
    {
    
        $headline = $this->input->post('headline');//$_POST['headline'];
        $source = $headline[1];//$this->input->post('source');
        $link = $this->input->post('link');
        $image_link = $this->input->post('img_link');
        $author = $this->input->post('author');
        $views = $this->input->post('view');
        $catagory = $this->input->post('catagory');
        
        $date_time=time();
        
        if ( $this->input->post('headline') !== FALSE ) {
            $this->Posting->posting($headline,$source,$link,$image_link,$author,$views,$catagory);

        }
    
    }

So I make this change to my controller, and have my model function accept all these parameters, and STILL only the headline "value" gets in, HOWEVER the rest go in as '0's.

Why does this input thinger only grab the first one... I'll try the $_POST['field'] on the rest.
#4

[eluser]tjackson1982[/eluser]
Puzzle becomes an impossibility.


I changed the posting function and this is what I get.

Controller
Code:
function posting_headline()
    {
    
        $headline = $_POST['headline'];
        $source = $_POST['source'];
        $link = $_POST['link'];
        $image_link = $this->input->post('img_link');
        $author = $this->input->post('author');
        $views = $this->input->post('view');
        $catagory = $this->input->post('catagory');
        
        $date_time=time();
        
        if ( $this->input->post('headline') !== FALSE ) {
            $this->Posting->posting($headline,$source,$link,$image_link,$author,$views,$catagory);
        }
    
    }

Model

Code:
function posting($headline_in, $source_in, $link_in,  $image_link_in,  $author_in, $catagory_in ) {
    
    
        $sql = "INSERT INTO headline (headline, source, link, image_link, author, catagory, date_time)
        VALUES (".$this->db->escape($headline_in).", ".$this->db->escape($source_in).", ".$this->db->escape($link_in).", ".$this->db->escape($image_link_in).", ".$this->db->escape($author_in).", ".$this->db->escape($catagory_in).", ".time().")";
        echo $sql;
        $this->db->query($sql);
    
        $date_time = time();
    
        $data = array(
           'headline' => $headline_in,
           'source' => $source_in,
           'link' => $link_in,
           'image_link' => $image_link_in,
           'author' => $author_in,
           'catagory' => $catagory_in,
           'date_time' => $date_time
         );
            
        //$this->db->insert('headline', $data);
    }

Output.

A PHP Error was encountered

Severity: Notice

Message: Undefined index: source

Filename: controllers/Posting.php

Line Number: 23
A PHP Error was encountered

Severity: Notice

Message: Undefined index: link

Filename: controllers/Posting.php

Line Number: 24
INSERT INTO headline (headline, source, link, image_link, author, catagory, date_time) VALUES ('Android Dev makes it big', NULL, NULL, 0, 0, 0, 1234307746)
A Database Error Occurred

Error Number: 1048

Column 'source' cannot be null

INSERT INTO headline (headline, source, link, image_link, author, catagory, date_time) VALUES ('Android Dev makes it big', NULL, NULL, 0, 0, 0, 1234307746)

Notice the Insert INTO has the correct Headline which was received by $_POST yet the Source and link are NULL and they too are using $_POST to get info.

Why does this only send one variable?
#5

[eluser]tjackson1982[/eluser]
Forms elements need to be ID by NAME NOT ID.

Final change is in the view

form:

Code:
<form method="post" name="posting_form"  action="posting_headline/">
        
Headline title
<input name="headline" type="text">
Source
<input name="source" type="text">
Source Link
<input name="link" type="text">
Any Image links
<input name="img_link" type="text">
Who wrote it
<input name="author" type="text">
How many views (may not be an input)
<input name="view" type="text">
What Catagory
<input name="catagory" type="text">

<input type="submit" value="Submit">

</form>

Notice the elements are all Names now...




Theme © iAndrew 2016 - Forum software by © MyBB