[eluser]symonel[/eluser]
Hi
This is gonna sound rather silly, but I get this weird error when I try to update a record in my 'products' table with the fields: product_id (int), product_name (varchar), product_description (varchar), product_price (int), seller_id (int). So here's my code:
This is my model function for getting a product:
Code:
function get_product($product_id)
{
$this->db->select('*');
$this->db->from('products');
$this->db->join('users', 'users.id = products.seller_id');
$this->db->where('product_id', $product_id);
$query = $this->db->get();
return $query;
}
and for updating a product:
Code:
function update_product($product, $id)
{
$this->db->where('product_id', $id);
$this->db->update('products', $product);
return $this->db->insert_id();
}
This is my controller:
Code:
function update_product($id = false)
{
if ($this->session->userdata('logged_in')) {
$data['user']['logged_in'] = TRUE;
} else {
$data['user']['logged_in'] = FALSE;
redirect('user/login');
}
$id_produs = $this->product_model->get_product($id);
$fields['product_name'] = 'product_name';
$fields['product_description'] = 'product_description';
$fields['product_price'] = 'product_price';
$produs = array(
'product_name' => $this->input->post('product_name', TRUE),
'product_description' => $this->input->post('product_description', TRUE),
'product_price' => $this->input->post('product_price', TRUE),
);
$data['single_product'] = $this->product_model->update_product($produs, $id_produs);
$this->load->view('product_view', $data);
}
And this is form in my view:
Code:
<?= form_open('bsc/update_product'); ?>
<p><label for="product_name">Product name:</label><br />
<input type="text" name="product_name" id="product_name" /></p>
<p><label for="product_description">Product description:</label><br />
<input type="text" name="product_description" id="product_description" /></p>
<p><label for="product_price">Product price:</label><br />
<input type="text" name="product_price" id="product_price" /></p>
<p><input type="submit" value="Update Product" /></p>
<?= form_close(); ?>
Quote:And what I get is this:
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysql_result could not be converted to string
Filename: database/DB_active_rec.php
Line Number: 450
Quote:An Error Was Encountered
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
UPDATE `products` SET `product_name` = 'Notebook HP 530', `product_description` = 'Intel Core Duo T2600 2.16GHz, RAM 1GB, 120GB', `product_price` = '250' WHERE `product_id` =
And that's it. No idea why this happens. Or why there doesn't seem to be a value for the id. Please help.