MySQL
  Home arrow MySQL arrow Page 5 - Online Photo Album Development using PHP and GD: Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
MYSQL

Online Photo Album Development using PHP and GD: Part 2
By: Frank Manno
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 34
    2004-04-22


    Table of Contents:
  • Online Photo Album Development using PHP and GD: Part 2
  • Code: Explained
  • Configurating
  • Connecting to the Database
  • 1,2,3, Testing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Online Photo Album Development using PHP and GD: Part 2 - 1,2,3, Testing
    ( Page 5 of 5 )

    First we test to see if the hidden variable "edit" has been set. This variable is set ONLY after an album has been edited. It may seem like we're working backwards, and that's what we're doing. We're checking to see if the album has been edited, then we check whether a specific album ID has been chosen. If neither of the two conditions is true, we display all albums in the database with a link to edit each.

    If the edit value has been set – in other words, we've edited our album details -- we test to ensure that each field has been completed. If not, we display an error message to the user, with an option to return back to the edit screen. If the fields have been completed, we connect to the database, and update the specific album. We then display a result page notifying that the album has been successfully updated:

     
    <p><span style="background-color: #ffff00;">} else if ( !$_POST['edit'] && !empty($_GET['album_id'])){ 
    <
    br />db_connect(); 
    <
    br />// Retrieve album information 
    <br />$sql "SELECT album_id, album_name, album_desc FROM albums WHERE album_id = 
    addslahes($_GET['album_id']); 
    <
    br />$result = @mysql_query$sql ) or die("Error retrieving record: " mysql_error()); 

    <
    br />while($row mysql_fetch_array$result )){ 
    <
    br />// Display edit page 
    <br />$msg .= 
    <form action="
    edit_albums.php" method="post">"
    <
    br />$msg .= 
    <table cellspacing="
    0" cellpadding="5" width="60%" border="0">"
    <
    br />$msg .= 
    <tbody>
    <tr>
    <td>Album Name:</td>
    <td>
    <input id="
    album_name" type="text" size="40" value="" name="album_name" /></td></tr>"
    <
    br />$msg .= 
    <tr>
    <td>Album Description:</td>
    <td><textarea id="
    album_desc" name="album_desc" rows="4" cols="30">" $row['album_desc'] . "</textarea></td></tr>"
    <
    br />$msg .= 
    <tr>
    <td>
    <input type="
    hidden" value="1" name="edit" /> 
    <input type="
    hidden" value="" name="album_id" /></td>"
    <
    br />$msg .= 
    <td>
    <input id="
    submit" type="submit" value="Continue" name="submit" />"
    <
    br />$msg .= "<a href="/administrator/del_albums.php?album_id=">Delete</a>"
    <
    br />$msg .= "</td></tr></tbody></table></form>"
    <
    br />$album_name $row['album_name']; 
    <
    br />} 
    <
    br />displayPage($msg"Editing Album " $album_name ":");</span
    <
    br />
    <
    br />Here we test to see if edit has NOT been set and whether an album ID HAS been 
    passed 
    (setthrough the URL query string (ieedit_albums.php?album_id=1). If 
    the condition is met (true), we display our edit album formwhich is simply a 
    table containing pre
    -filled fieldsThe value of each field is retrieved from 
    our database
    via our SQL SELECT query:</p>
    <
    p>
    <
    td />
    <
    input type="hidden" value="1" name="edit" /> 
    <
    input type="hidden" value="" name="album_id" /></p>
    <
    p>This is where our hidden fields resideThe first field is our edit variable 
    that has been tested above
    The second holds the ID value of the current album 
    we are editing
    These hidden fields are passed to the processing page as POST 
    variables once the form is submitted
    .</p>
    <
    p>The last link we provide is a delete linkwhich allows us to delete the current 
    album we are editing
    Herewe call the del_album.php script, and pass to it our 
    album
    's ID.</p>
    <p><span style="background-color: #ffff00;">// Display album summaries 
    <br />} elseif ( !$_GET['
    album_id'] ){ 
    <br />db_connect(); 
    <br />// Retrieve all album information 
    <br />$sql = "SELECT album_id, album_name FROM albums"; 
    <br />$result = @mysql_query( $sql ) or die( "Error retrieving records: " . mysql_error() 
    ); 
    <br />$i = 0; 
    <br />while($row = mysql_fetch_array($result)){ 
    <br />if (( $i % 2 ) == 0 && ( $i != 0 )){ 
    <br />$msg .= (" 
    </tr />
    <tr />"); 
    <br />} 
    <br />$msg .= (" 
    <td />" . ($i + 1) . ". <a href="/administrator/'
    edit_albums.php?album_id=">" $row['album_name'] . 
    </td />"
    ); 
    <
    br />$i++; 
    <
    br />} 
    <
    br />displayPage$msg"Edit Albums"false ); 
    <
    br />} 
    <
    p>This last test checks to see whether or not an album ID has been set. If not
    we display each album namein the databasein an HTML table and give the option 
    of editing the album via a hyperlink
    :</p>
    <
    p>Now that we've completed the option of adding and editing our albums, its time 
    to go ahead to add some pictures!</p>
    <p>Our del_albums.php script is quite simple:</p>
    <p><!--p<-->include_once("../include/config.php"); 
    <br />// No album id has been selected 
    <br />if( !$_GET['
    album_id'] ){ 
    <br />// Display error message to user 
    <br />$msg .= "Album not selected. Please choose an album you wish to delete!"; 
    <br />$msg .= " 
    <br /><a href="/administrator/edit_album.php">Edit albums</a>"; 
    <br />displayPage($msg, "Error Selecting Album"); 
    <br />} else { 
    <br />db_connect(); 
    <br />// Delete specified album 
    <br />$sql = "DELETE FROM albums WHERE album_id = " . addslashes($_GET['
    album_id']); 

    <br />$result = @mysql_query($sql) or die("Error deleting record: " . mysql_error()); 

    <br />// Display success to user 
    <br />$msg .= "Album has been successfully deleted! 
    <br /><a href="/administrator/'
    index.php'">Return to Admin Menu</a>"; 
    <br />displayPage($msg, "Album Deleted!"); 
    <br />} 
    <br />

    </p></a>"; displayPage($msg, "Error Selecting Album"); } else { db_connect(); // Delete specified album $sql = "DELETE FROM albums WHERE album_id = " . addslashes($_GET['
    album_id']); 
    $result = @mysql_query($sql) or die("Error deleting record: " . mysql_error()); 
    // Display success to user $msg .= "Album has been successfully deleted! "; displayPage($msg, "Album Deleted!"); } 


    </a />"; displayPage($msg, "Error Selecting Album"); } else { db_connect(); // Delete 
    specified album $sql = "DELETE FROM albums WHERE album_id = " . addslashes($_GET['
    album_id']); 
    $result = @mysql_query($sql) or die("Error deleting record: " . mysql_error()); 
    // Display success to user $msg .= "Album has been successfully deleted! "; displayPage($msg, 
    "Album Deleted!"); } 

     
    </a /></span></p>

    The del_albums.php script is simply checks to see that an album ID was passed to it. If not, an error message is displayed to the user. If an album ID has been passed, we create an SQL DELETE statement that removes the specified album from the database.



     
     
    >>> More MySQL Articles          >>> More By Frank Manno
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...





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