PHP
  Home arrow PHP arrow Page 5 - Building PHP Applications With Macrome...
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Building PHP Applications With Macromedia Dreamweaver MX
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 32
    2002-12-18

    Table of Contents:
  • Building PHP Applications With Macromedia Dreamweaver MX
  • Hooking Up
  • Test Drive
  • Breaking Ground
  • Naming Names
  • Bringing In The Database
  • Appearances Are Everything
  • In And Out
  • I, Robot
  • Weaving The Web

  • 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


    Building PHP Applications With Macromedia Dreamweaver MX - Naming Names


    (Page 5 of 10 )

    Once your site has been set up, it's time to get started with a simple example - a page that display PHP environment settings via the phpinfo() function.

    Dreamweaver provides you with an easy way to get started with building a PHP script - pop open the File -> New menu, and select "Dynamic Page" and "PHP" from the pre-defined templates.



    You can now add the function call to phpinfo() in this page - switch to the code view using the View -> Code menu option, and type the following code into your document:

    <?php phpinfo(); ?>


    Save the file, and have Dreamweaver preview it for you via the toolbar icon (you can also hit the F12 key) and a new browser window should pop up with the output of the script.



    If you're using PHP, you're going to be doing a lot of form processing - let's see how you can speed up the process in Dreamweaver. First, create a simple, properly-formatted HTML form using a combination of the "Tables" and "Forms" tabs on the "Insert" panel - this form should contain two text input areas, one named "name" and the other named "comment".



    Add a couple of submit and reset button and the form is ready for action.



    Here's the code:

    <html> <head> <title>Untitled Document</title> </head> <body> <form action="this.php" method="post"> <table width="75%" border="0"> <tr> <td>Name</td> <td><input name="name" type="text"></td> </tr> <tr> <td>Comment</td> <td><textarea name="comment" cols="" rows=""></textarea></td> </tr> <tr> <td><input name="submit" type="submit" value="Submit"></td> <td><input name="Reset" type="reset" value="Reset"></td> </tr> </table> </form> </body> </html>
    Now comes the interesting part - integrating PHP business logic into this example. Click the "PHP" tab that should have appeared on your "Insert" panel, and take a look at the functions it provides:



    Pretty basic: you can insert PHP code to access POST, GET, cookie and session variables, include() and require() files, and attach programming constructs like "if" and "else" statements.

    Now, you probably already know how PHP form processing typically works. A form processing script contains two logical blocks - one displays the empty form and the other processes the user input submitted. Therefore, the first thing to do is to insert an "if" conditional statement at the top of the code - just click on the "If" button and Dreamweaver will do it for you:

    <?php if ?> // form code
    Next, you need to check if the form has been submitted or not, via the "submit" form variable. Use the "Form Variables" button, and write some code around what Dreamweaver inserts for you:

    <?php if (!$HTTP_POST_VARS['submit']) { ?> // form code
    Once you've wrapped your empty form in the "if" branch of the conditional, you need to add form processing logic to the "else" branch. Use the "else" button on the toolbar, and let Dreamweaver insert it for you.

    <?php } else { ?>
    This "else" branch of the script is supposed to merely display the data entered by the user. You can do this via the echo() command, also accessible via a button on the PHP toolbar.

    <?php echo $HTTP_POST_VARS['name']; ?>
    Here's the final script:

    <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if (!$HTTP_POST_VARS['submit']) { ?> <form action="this.php" method="post"> <table width="75%" border="0"> <tr> <td>Name</td> <td><input name="name" type="text"></td> </tr> <tr> <td>Comment</td> <td><textarea name="comment" cols="" rows=""></textarea></td> </tr> <tr> <td><input name="submit" type="submit" value="Submit"></td> <td><input name="Reset" type="reset" value="Reset"></td> </tr> </table> </form> <?php } else { ?> <table width="75%" border="1" cellspacing="5" cellpadding="5"> <tr> <td width="39%">Name</td> <td width="61%"><?php echo $HTTP_POST_VARS['name']; ?></td> </tr> <tr> <td>Comments</td> <td><?php echo $HTTP_POST_VARS['comment']; ?></td> </tr> </table> <?php } ?> </body> </html>
    Now, you can easily test this code using the "Preview" button, as discussed earlier. Here's the output:





    It should be noted that Dreamweaver's attempt to make PHP scripting a point-and-click exercise, as demonstrated via the example above, isn't really an unqualified success - the functionality provided on the PHP toolbar is extremely limited, and most developers would find it more efficient to type in PHP statements themselves, rather than clicking their way through the buttons on the PHP tab. Don't be disappointed, though - although the program fails at this task, it excels when it comes to building database-driven dynamic pages (more on this on the next page).

    Once you're happy with the way your script is working, you can transfer the file to your remote server (named "cerberus" in this case). Pop open the "Files" panel on the right side of the workspace, select the "local view", and use the arrow buttons to transfer files from your local site to the remote site.



    You can also perform transfers in the other direction, by changing to the "remote view" and either putting or getting files to/from the server.

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


     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT