AndrewMori 0 Newbie Poster

Hi.

I am looking for support from the cakephp environment but i thought i would try DaniWeb out too :)

I am learning how to add, edit and delete entries in database tables from cakephp script. So far i can add and delete just fine, but i am struggling to edit entires. here is how i would add an entry to a database.

if (!empty($this->data)) 
{
	$this->SupportTicket->create();
	$data = $this->data;
	$data['SupportTicket']['user_id'] = $this->Auth->user('id');
        // setting some information
	$data['SupportTicket']['status'] = $this->statuses[1];
	$this->data = $data;
	if ($this->SupportTicket->save($this->data))
	{
	       $this->Session->setFlash('Support ticket created');
	}
        else
	{
              $this->Session->setFlash('Error Msg ');
	}
}

This seams to work fine. Now i want to call up that entry (which i can also do successfully) and edit some fields, and then save it back to the database table. I have tried this as follows without success.

if(!empty($support_tickets))
{
	$this->Support_ticket = $support_tickets;
	//pre($this->Support_ticket); this print displays correct data
	$this->data = $support_tickets;
	//setting status to pending. changed from open
	$this->data['Support_ticket']['status'] = $this->statuses[1];
        // mem_id is orignally 0
  	$this->data['Support_ticket']['mem_id'] = 5;
  	//pre($this->data); when uncommented this shows 
        //correctly edited entry, ready to shove back into DB. or 
       //more precisly update in the DB.
  			
  	$this->Support_ticket->save($this->data);
        // i am getting an error message saying:
        //Call to a member function save() on a non-object
}
etc
etc

is this because of some naming convention error i am making (even though i can display the correctly updated entry) or am i missing something simple?

any help will be greatly appreciated.

Andrew

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.