Welcome Guest, Not a member yet? Register   Sign In
problem with posts update/edit
#1

[eluser]Tetek[/eluser]
Hi all
I have a problem with editing posts in my blog. look at this.

controller
Code:
function editnews2()
    {
        
        $_iNews = (int) $this->uri->segment(3);
        $this->db->where('id', $_iNews);
        $data['query'] = $this->db->get('entries');
        $this->load->view('editnews2', $data);

    }
function news_update()
    {
    $this->db->where('id', $this->uri->segment(3));
    $this->db->update('entries', $_POST);
    redirect('blog'.$_POST['id']);
    }

Editnews view
Code:
<html>
<head>
<link rel="stylesheet" href="/css/style.css" type="text/css" />
<?=$this->load->view('header');?>
</head>
<body>

<div id="main">

    &lt;?php foreach($query->result() as $row):?&gt;
    &lt;?=form_open('blog/news_update/'.$this->uri->segment(3));?&gt;

        <p>&lt;input type="text" name="title" value="&lt;?=$row-&gt;title?&gt;" />&lt;/input&gt;</p>
        <p>&lt;textarea&gt;&lt;?=$row->body?&gt;&lt;/textarea&gt;</p>
        <p>&lt;input type="submit" value="Zapisz zmiany" /&gt;</p>
    &lt;/form&gt;

    &lt;?php endforeach;?&gt;
    
</div>
</div>

&lt;/body&gt;
&lt;?=$this->load->view('footer');?&gt;
&lt;/html&gt;

ERROR:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined index: id

Filename: controllers/blog.php

Line Number: 110
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\system\libraries\Exceptions.php:164)

Filename: helpers/url_helper.php

Line Number: 455

Can u see where is the mistake?
#2

[eluser]Seppo[/eluser]
Probably it´s here.
Code:
redirect('blog'.$_POST['id']);
Insted of $_POST['id'] you shoud use $this->uri->segment(3)
#3

[eluser]xwero[/eluser]
I'm going to make a run down of (possible) problems i see

- the id isn't posted because there is no input field with the name id
- the $data['query'] should return only one row so the query code would be $this->db->get('entries')->row(); (php5)
- because there is only one row you don't need the foreach in your view
- the redirect should be redirect('blog/'.$_POST['id']); i guess
- the $_POST should be validated before you add it to the sql statement
#4

[eluser]David Rothera[/eluser]
The script is saying it cant redirect you because some output has already been sent to the browser when it gave you the error about the undefined index.

Could you try echo out $_iNews; right after you have set it to make sure it is what you expect it to be (namely and integer).




Theme © iAndrew 2016 - Forum software by © MyBB