CodeIgniter Forums
Insert Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Insert Error (/thread-30069.html)

Pages: 1 2


Insert Error - El Forum - 05-02-2010

[eluser]chicadeas[/eluser]
I am new to Codeigniter. I get this message when I try to insert info into my database. Need help.
Message: Cannot modify header information - headers already sent by (output started at /home/danadria/public_html/system/application/controllers/blog.php:1)


Insert Error - El Forum - 05-02-2010

[eluser]pickupman[/eluser]
[quote author="chicadeas" date="1272807940"]I am new to Codeigniter. I get this message when I try to insert info into my database. Need help.
Message: Cannot modify header information - headers already sent by (output started at /home/danadria/public_html/system/application/controllers/blog.php:1)[/quote]

This means you may have a empty line at the start of your file ie:
Code:
(blank line here)
<?php
class Your_file_begins_here
Make sure the opening php tag is on line 1 of you file. You may also get this problem if you leave an empty line after a closing php tag. To save yourself some headaches, you may leave off the closing php tag for a file.


Insert Error - El Forum - 05-03-2010

[eluser]chicadeas[/eluser]
Thanks pickupman for the reply. I believe you were right and I have corrected this problem. In the meantime I have deleted the scaffolding code and inserted new code which doesn't use scaffolding, for working with my data base. The new code is $data['query'] = $this->db->get('entries'); With this code I get an error telling me that "entries' is a nonobject. It worked with scaffolding but not with the query code.


Insert Error - El Forum - 05-03-2010

[eluser]pickupman[/eluser]
Quote:The new code is $data[‘query’] = $this->db->get(‘entries’); With this code I get an error telling me that “entries’ is a nonobject. It worked with scaffolding but not with the query code.

That's odd. That line should not throw that error. That would throw a database error for table not found. Could you post your code around that line?


Insert Error - El Forum - 05-03-2010

[eluser]Ivar89[/eluser]
The error is not because of that code(because the one you are whowing is correct)
the error is caused by a var $entries somwhere that has no data(maybe a spelling error somewhere

paste the code please ^^


Insert Error - El Forum - 05-03-2010

[eluser]chicadeas[/eluser]
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
}

function index()
{
$data['title'] = "My Real Title";
$data['heading'] = "My Real Heading";
$data['query'] = $this->db->get('entries');
$this->load->view('blogview', $data);
}
}
?>


advabnce thanks


Insert Error - El Forum - 05-03-2010

[eluser]pickupman[/eluser]
How about your view? I am guessing that somewhere you have either $this->entries or $entries, however, $entries has not been set. Also, when posting code please use the code button in the menu above the message box.


Insert Error - El Forum - 05-03-2010

[eluser]Zack Kitzmiller[/eluser]
I'm willing to bet that you're looking through $entries->result_array() or something in your view, when you actually want to be looping through $query->result_array(), or other such thing.

You haven't defined an object called 'entries' anywhere in the code you've shown us.


Insert Error - El Forum - 05-03-2010

[eluser]chicadeas[/eluser]
entries is the name of a table in my database. I assume that it is configured when the db class is called. I can insert and extract info from my "entries" table by using standard php queries. This is my view code:

Code:
<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>
<h1>&lt;?php echo $heading;?&gt;</h1>

&lt;?php foreach($query->() as $row):?&gt;
<h3>&lt;?=$row->title?&gt;</h3>
<p>&lt;?=$row->body?&gt;</p>
<hr>

&lt;?php endforeach;?&gt;

    
&lt;/body&gt;
&lt;/html&gt;



Insert Error - El Forum - 05-03-2010

[eluser]Zack Kitzmiller[/eluser]
There's your problem.

Code:
foreach($query->() as $row):

should be

Code:
foreach($query->result() as $row):