[eluser]TheFuzzy0ne[/eluser]
Are any of your calls to set_value() actually working as expected. I see quite a few potential problems.
I'm struggling to follow the flow of your code because you're missing an opening curly braces here:
Code:
function edit($account_id='', $platform =''){
if($account_id > ''){
$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
if(isset($query)) // here
if ($query->num_rows() > '')
{
Here are some suggestions (that hopefully point out some other logic errors):
Code:
function edit($account_id='', $platform =''){
// if($account_id > '') {
if ($account_id) {
$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
// if(isset($query)) { // $query is already set to the return value of the function call above.
if ($query) {
// if ($query->num_rows() > '') // num_rows() returns an integer.
if ($query->num_rows() > 0)
{
$row = $query->row_array();
}
/* // Or maybe:
if ($query AND $query->num_rows() != 0) {
$row = $query->row_array();
*/
$data['account_id'] = '';
$data['platform'] = '';
$data['name'] = '';
$data['location_city'] = '';
$data['location_country'] = '';
$data['status'] = '';
$data['region'] = '';
$data['link'] = '';
$data['type'] = '';
$data['faccount_id']['value'] = $row['account_id'];
$data['fplatform']['value'] = $row['platform'];
$data['fname']['value'] = $row['name'];
$data['flocation_city']['value']= $row['location_city'];
$data['flocation_country']['value'] = $row['location_country'];
$data['fstatus']['value'] = $row['status'];
$data['fregion']['value'] = $row['region'];
$data['flink']['value'] = $row['link'];
$data['ftype']['value'] = $row['type'];
}
// if (isset($account_id)) { // $account_id is already set to whatever was passed into the controller method, or the default value.
// If we've got this far, then we must have a valid account_id, so no point checking for it anyway.
$this->form_validation->set_rules('account_id', 'Account ID', 'trim|required');
$this->form_validation->set_rules('platform', 'Platform', 'trim|required');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'trim|required');
$this->form_validation->set_rules('location_city', 'City', 'required');
$this->form_validation->set_rules('location_country', 'Country', 'required');
$this->form_validation->set_rules('region', 'Region', 'required');
$this->form_validation->set_rules('link', 'Link', 'trim|required');
$this->form_validation->set_rules('type', 'Type', 'trim|required');
if($this->form_validation->run()) {
if ($query = $this->dashboard_model->update_account()) { //If successful update
$data['message'] = ' - Update complete!';
} else {
$data['message'] = 'There was an error, update not complete.';
}
}
// Can't you set this at the top of the method? Where are you checking the validity of $platform?
// I would recommend setting a default for it.
$data['account'] = $this->dashboard_model->get_account($account_id, $platform);
// Shouldn't this be loaded at all times, not just when the edit is successful?
$this->load->view('manage/edit',$data);
}
// What happens when there's no account ID specified, or it doesn't exist?
}