Welcome Guest, Not a member yet? Register   Sign In
Insert Error
#1

[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)
#2

[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.
#3

[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.
#4

[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?
#5

[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 ^^
#6

[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
#7

[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.
#8

[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.
#9

[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;
#10

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

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

should be

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




Theme © iAndrew 2016 - Forum software by © MyBB