CodeIgniter Forums
What's Broken? - 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: What's Broken? (/thread-33593.html)



What's Broken? - El Forum - 09-01-2010

[eluser]Bionicjoe[/eluser]
I changed something awhile back & I guess I didn't test it. Now I can't fix whatever I changed?

Trying to insert a record.
I get error
Quote:Message: Undefined index: addupdate
Filename: controllers/outage.php

NOTE: If I uncomment the redirect I'll see the error & the page redirects quickly with the update inserted into the DB. But why the error?

Code:
function addupdate() {
      //Submit an update to the 'UPDATES' table.
      $id = $this->uri->segment(3);
      $this->load->model('outage_model','',TRUE);
      $this->outage_model->addupdate($_POST['addupdate'], $_POST);
      $link = array('outage/editoutage', $_POST['outageid']);
    //redirect($link,'refresh');
  }

Model
Code:
function addupdate($id, $data)
    // Update one outage record
    {
      $this->db->where('outageid', $id);
      $this->db->insert('updates', $data);
    }



What's Broken? - El Forum - 09-01-2010

[eluser]WanWizard[/eluser]
The only line in your example that contains that index is
Code:
$this->outage_model->addupdate($_POST['addupdate'], $_POST);

Since you don't tell us where this error occured, I assume that $_POST doesn't contain a field called 'addupdate'.


What's Broken? - El Forum - 09-01-2010

[eluser]jdav3579[/eluser]
Can you post the form?


What's Broken? - El Forum - 09-01-2010

[eluser]jdav3579[/eluser]
Sorry WanWizard, was reading it when you posted. I agree though.


What's Broken? - El Forum - 09-01-2010

[eluser]Bionicjoe[/eluser]
Oh wow. I really don't understand things I think.

'addupdate' is the name of my function in the model.
Code:
echo form_open('outage/addupdate');
    echo form_hidden('outageid', $outage[0]->outageid);?>
    <hr>
    <table id="outageform">
        <col />
        <tr><td>Add Update</td><td>&lt;?php echo form_textarea($update_textarea);?&gt;</td></tr>
        <tr><td>          </td><td>&lt;?php echo form_submit('', 'Add an Update');?&gt;</td></tr>
    </table>
    &lt;?php echo form_close(); //End form to add updates



What's Broken? - El Forum - 09-01-2010

[eluser]WanWizard[/eluser]
Possible.

But the error said "Undefined index". Which has nothing to do with method names, an index is an array index. And as $_POST is an array, and 'addupdate' in key in that array that you reference, it is my assumption that that like is causing the error.


What's Broken? - El Forum - 09-01-2010

[eluser]Bionicjoe[/eluser]
Thanks. Figuring things out now, but I have a new problem.

In several Form Submits I get the following error just before the redirect, but all data makes it into the DB.

Quote:Message: preg_match() expects parameter 2 to be string, array given
Filename: helpers/url_helper.php
Line Number: 532

I'd really like to understand this error.


What's Broken? - El Forum - 09-01-2010

[eluser]WanWizard[/eluser]
If this is your level of understanding, perhaps you should consider some additional development/PHP training?

The message is very clear. You have called a function defined in the URL helper with the wrong type of parameter.
Simply looking in the file mentioned, at the line mentioned, would have told you want you did wrong.
I checked, and it's pretty obvious, but I leave it to you as a training excercise. Wink


What's Broken? - El Forum - 09-01-2010

[eluser]Bionicjoe[/eluser]
I'm an idiot.
I understood what the error was saying, but couldn't figure out why this had shown up 'all of the sudden'. Think I copy/pasted something awhile ago & just didn't check it.

Sleep helps.

Code:
$link = 'outage/editoutage/' . $_POST['outageid'];
    redirect($link,'refresh');



What's Broken? - El Forum - 09-02-2010

[eluser]WanWizard[/eluser]
hehehe...

I solved that problem with an espresso machine on my desk. Smile