Welcome Guest, Not a member yet? Register   Sign In
You must use the "set" method to update an entry.
#1

[eluser]jerrac[/eluser]
I'm running into this error:
Quote:A Database Error Occurred

You must use the "set" method to update an entry.

Filename: /home/reagand/dev/ldapwrangler/application/models/directories_model.php

Line Number: 38

I've read several topics on this problem, but none seem to apply to my case. People are either forgetting to pass the data through, having errors with null values in their database, or forgetting the use the $this->db->set(); method.

The $this->db->set(); method does not need to be used with $this->db->insert('table',$dataarray); unless I'm reading http://ellislab.com/codeigniter/user-gui...ecord.html wrong.

I am passing my data through correctly, as you can see with in my code.

directories_model.php:
Code:
class Directories_model extends CI_Model
{
public $list;

public function __construct()
{
  parent::__construct();
  $this->load->database();
}

public function get_directories()
{
  $this->list = array();
  $this->load->model('directory_model');
  $query = $this->db->get_where('directories');
  $result = $query->result_array();
  foreach($result as $row)
  {
   $this->list[$row['name']] = $this->directory_model->get_directory($row['name']);
  }
}

public function get_list()
{
  return $this->list;
}

public function add_directory($data)
{
  $this->db->insert('directories',$data);//this is line 38
}
}

The relevant controller code:
Code:
$formdata = array();
if(!$this->input->post('name'))
$formdata['name'] = $this->input->post('name');
if(!$this->input->post('host'))
$formdata['host'] = $this->input->post('host');
if(!$this->input->post('port'))
$formdata['port'] = $this->input->post('port');
if(!$this->input->post('binddn'))
$formdata['binddn'] = $this->input->post('binddn');
if(!$this->input->post('basedn'))
$formdata['basedn'] = $this->input->post('basedn');
if(!$this->input->post('password'))
$formdata['bindpass'] = $this->input->post('password');
$result = $this->directories_model->add_directory($formdata);
$this->load->view('header');
if($result)
{
$data['title']="Added Directory";
$this->load->view('ldapwrangler/add_dir_success',$data);
}
else
{
$data['title'] = "Error";
$this->load->view('ldapwrangler/add_dir_error',$data);
}
$this->load->view('footer');

Here's my add_directory view:
Code:
<div class='container'>
&lt;?php
$urlstr = 'ldapwrangler/directories/add';
echo form_open($urlstr,array('class'=>'form-horizontal','id'=>'adddirform'));
?&gt;
<div class='control-group'>
<label class='control-label' for='name'>Name</label>
<div class='controls'>
  &lt;input type="text" name="name" id="name" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='host'>Host</label>
<div class='controls'>
  &lt;input type="text" name="host" id="host" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='port'>Port</label>
<div class='controls'>
  &lt;input type="text" name="port" id="port" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='binddn'>Bind DN</label>
<div class='controls'>
  &lt;input type="text" name="binddn" id="binddn" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='password'>Password</label>
<div class='controls'>
  &lt;input type="text" name="password" id="password" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='passwordcheck'>Password Check</label>
<div class='controls'>
  &lt;input type="text" name="passwordcheck" id="passwordcheck" class="input-xlarge text"&gt;
</div>
</div>
<div class='control-group'>
<label class='control-label' for='basedn'>Base DN</label>
<div class='controls'>
  &lt;input type="text" name="basedn" id="basedn" class="input-xlarge text"&gt;
</div>
</div>
<div class="form-actions"><button name="" type="submit" class="btn btn-primary">Save</button><button name="" type="reset" class="btn btn-danger">Reset</button></div>
&lt;/form&gt;
</div>

And, in case the null value problem is it, here's my table structure:
Code:
CREATE TABLE directories (
  id int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `host` varchar(255) NOT NULL,
  `port` int(11) DEFAULT NULL,
  binddn text,
  bindpass varchar(255) DEFAULT NULL,
  basedn text,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Any clues?
#2

[eluser]jerrac[/eluser]
Ah, logic problem. In the controller I was checking if the $this->input->post returns were false when I should have been checking if they were true. Always the small stuff.




Theme © iAndrew 2016 - Forum software by © MyBB