PHP
  Home arrow PHP arrow Page 8 - PHP and COM
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and COM
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2002-04-23

    Table of Contents:
  • PHP and COM
  • Striving To Excel
  • The Number Game
  • Export Potential
  • Keeping It Simple
  • Access-ing The Web
  • All For One, And One For All
  • New Coins For Old
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP and COM - New Coins For Old


    (Page 8 of 9 )

    If the user chooses to add a new record, the value of $nextopid is set to "add_process". And when the PHP script is called to process the form data, this is the code block that gets executed.

    <?php if($nextopid == "add_process") { // open connection $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); // run query $Query = "INSERT INTO coins(name, country, weight, year, remarks) VALUES('".trim($name)."','".trim($country)."',".trim($weight).",".trim($ year ).",'".trim($remarks)."')"; $RS_Record = $DB_Conn->Execute($Query); // redirect browser to list header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "add" processor } ?>
    Similarly, when the script is called to edit a record, this code block will get executed.

    <?php if($nextopid == "edit_process") { // open connection $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); // execute query $Query = "UPDATE coins SET name = '".trim($name)."',country = '".trim($country)."',weight = ".trim($weight).",year = ".trim($year).",remarks = '".trim($remarks)."' WHERE id = $id"; $RS_Record = $DB_Conn->Execute($Query); // redirect browser back to list header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "edit" processor } ?>
    Fairly simple and self-explanatory, this - depending on the type of operation, an appropriate SQL query is generated and executed.

    Finally, record deletion. This is activated by calling the script with the value of $nextopid set to "delete", and an additional record ID to identify which record is to be deleted. Take a look:

    <?php if($nextopid == "delete") { // delete selected records $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); $Query = "DELETE FROM coins WHERE id = $id"; $RS_Record = $DB_Conn->Execute($Query); header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "delete" condition } ?>
    Short and sweet. And when you try the entire thing out, you'll see that you can add, edit and delete records to the Access database, via the COM object. Ain't it cool?

    More PHP Articles
    More By Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway