0

Just to make it fast, here are some of my shortened codes:

Controllers:

public function edit()  // assign positions to array $data["position"]
{
    $data["position"] = $this->My_Model->get_query_array("SELECT * FROM Position_List");
}

public function update() // after submission, call this method
{   
    echo $getdata['Position_Code'] = $_POST['position'];
    // returns error (undefined index), no result for position
}

Model:

public function get_query_array($query_statement) // my query
{
    $query = $this->db->query($query_statement);
    return $query->result();
}

View

<label for="position">Change Position</label>
<select name="position" id="position"  >
<option value=""></option>
<?php
foreach($position as $row)
{
    echo "<option value='".$row->Position_Code."'".($row->Position_Code==$Default_Position?"selected='selected'":"").">".$row->Position_Name."</option>";
}
?>
</select>

For clearer explanation of my problem:
1. controller: edit() method works fine - check
2. model: get_query_array() returns the query result - check
3. view: the foreach loop returns all the positions I queried - check
4. controller: update() method returns this error upon submission: - ERROR!

A PHP Error was encountered

Severity: Notice

Message: Undefined index: position

Filename: controllers/Home.php

How come it says undefined index although the loop displays the positions and name="position" id="position" are present from the view.

I already tried using var_dump($position) and print_r($position) and it returns all the positions from the database without any NULL values.

Please help. Thanks!

Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
Jorz
  • 358
  • 5
  • 22

0 Answers0