phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Database: Updating Data

Tag: framework, zend, zend framework, database, update, data   Category: PHP Framework
post: 12 Apr 2008 read: 1,679


Zend Framework Database Step By Step Tutorial - Part 7: In this post, we will see action for updating data. Open your "UserController.php" within application/controller. Enter following new action:

  public function processeditAction()
  {
    $params = array('host'		=>'localhost',
	                'username'	=>'root',
					'password'  =>'admin',
					'dbname'	=>'zend'
	               );
	$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
	$request = $this->getRequest();
    
	$sql = "UPDATE `user` SET  `first_name` = '".$request->getParam('first_name')."',
	                           `last_name` = '".$request->getParam('last_name')."',
							   `user_name` = '".$request->getParam('user_name')."'
	        WHERE id = '".$request->getParam('id')."'";
	$DB->query($sql);
	
    $this->view->assign('title','Editing Process');
	$this->view->assign('description','Editing succes');  	
		
  }

Then, create a file named "processedit.phtml" within views/scripts/user. Enter following code:


<? include "header.phtml"; ?>
  <h1><?=$this->escape($this->title);?></h1>
  <h2><?=$this->escape($this->description);?></h2>
  <a href="list">Member List</a>
<? include "footer.phtml"; ?>

Ok, try to update data from edit form.



Series this article:
Zend Framework Database: Intro
Zend Framework Database: Creating Input Form
Zend Framework Database: Inputing Data to Database
Zend Framework Database: Inserting Expressions to a table
Zend Framework Database: Creating List of Data
Zend Framework Database: Creating Editing Form
Zend Framework Database: Updating Data
Zend Framework Database: Updating Data Use Update Query From Zend Framework
Zend Framework Database: Deleting Data
Zend Framework Database: Delete Query Style
Zend Framework Database: Summarizing Action Controller

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

1 Responses to Zend Framework Database: Updating Data:

this isa very good tutorial for beginners like me. Everything works fine so far. I have two problems that i have failed to resolve which are:

1) when i try to view the members in a list ie list.html i get the error below but the table and its headers display well:
Fatal error: Cannot use string offset as an array in C:\apache\htdocs\koba\application\views\scripts\user\list.phtml on line 25


2)on the processedit.html i get the follwing error:

Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 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 ''first name'='', 'last_name='', 'user_name='', WHERE id=''' at line 1' in C:\apache\htdocs\koba\library\Zend\Db\Statement\Pdo.php:238 Stack trace: #0 C:\apache\htdocs\koba\library\Zend\Db\Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array) #1 C:\apache\htdocs\koba\library\Zend\Db\Adapter\Abstract.php(405): Zend_Db_Statement->execute(Array) #2 C:\apache\htdocs\koba\library\Zend\Db\Adapter\Pdo\Abstract.php(205): Zend_Db_Adapter_Abstract->query('UPDATE user SE...', Array) #3 C:\apache\htdocs\koba\application\controllers\UserController.php(115): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE user SE...') #4 C:\apache\htdocs\koba\library\Zend\Controller\Action.php(502): UserController->processeditAction() #5 C:\apache\htdocs\koba\library\Zend in C:\apache\htdocs\koba\library\Zend\Db\Statement\Pdo.php on line 238

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting