Welcome Guest, Not a member yet? Register   Sign In
Assigning Session variable to an attribute after Insert/update
#1

[eluser]quest13[/eluser]
Hi,I am new to CI and I need help on the following issue due to which my entire work is stalled.

After I insert my product details, i want to assign session variable to Productid which is the primary key of the table.Later, I want to use the same Productid when I update or Back or Skip to the various interview stages of product updation.

I insert 3 fields initially, but I update as I move on further ( like a interview navigation).On doing so, at times, either I come back to the previous page or skip certain page.In this scenario, I am not able to keep the Productid in session. ( I am new to CI, I know how it is done otherwise). Ofcourse, $this->db->insert_id() or $this->db->affected_rows()helped certain extent but fails when I go back or skip.


$query=$this->db->query("INSERT INTO product(productname,qty,price) VALUES('".$prodname."','".$qty."','".$price."')");

$lastrow = $this->db->insert_id();

if($lastrow >0){
$row = $query->row_array();
$this->session->sess_create();
$this->session->set_userdata($row);
$id=$row['PropertyId'];


The above code gives an error of "Call to a member function row_array() on a non-object"
The same in case of "result_array()" too.

When I tried to use the $id in other function, it doesn't recognize it.I think the session is not set at all for the product id.

Any help on this is highly appreciated.

Thank you in advance.
#2

[eluser]bigtony[/eluser]
I personally use Active Record for db stuff, but from memory I don't think sql insert commands return any rows. Why not just store the inserted id into the session?
Code:
$this->session->set_userdata($lastrow);
And then elsewhere you can retrieve the value in order to do a sql select.
Also, you don't need $this->session->sess_create() (that function is not even in the documentation!)
#3

[eluser]quest13[/eluser]
Thank you, I will try it and get back to you




Theme © iAndrew 2016 - Forum software by © MyBB