Home arrow MySQL arrow Page 3 - Online Photo Album Development using PHP and GD: Part 2

Configurating - MySQL

In this part Frank will explain how to code the photo album using PHP and MySQL. This is the second part of his series and focuses on building the user interface.

  1. Online Photo Album Development using PHP and GD: Part 2
  2. Code: Explained
  3. Configurating
  4. Connecting to the Database
  5. 1,2,3, Testing
By: Frank Manno
Rating: starstarstarstarstar / 34
April 22, 2004

print this article



Our config file initializes our connection variables: $db_server, $db_user, $db_pass, and $db_name. These variables are used in the db_connect() function which simply connects to our database system (in this case MySQL) and selects the album database we'll be using in our application.

Our create_album.php file is simply a form that accepts user-input, and submits the data to our processing script. Once the data is entered by the user, our processor script checks to see if all the fields have been completed; if not, an error message is displayed. If all fields are complete, the album data is added to the database. We'll call our processor script add_album.php:

br />// Verify that all form elements are completed 
<br />if (empty($_POST['album_name']) || empty($_POST['album_desc'])){ 
br />displayPage("Please complete all required fields! 
<br /><a href="
/administrator/'new_album.php'">Go Back</a>""Error Adding Album!"); 
br />die(); 
br />} 
br />// Connect to database 
<br />db_connect(); 
br />$sql "INSERT INTO albums VALUES(0, '" addslashes($_POST['album_name']) . 
"', '" addslashes($_POST['album_desc']) . "', 0, '', '')"
br />$result = @mysql_query($sql) or die("Error inserting record: " mysql_error()); 

br />if ($result){ 
br />// Notify use that album was successfully created. 
<br />$msg .= "Album <strong>" $_POST['album_name'] . "</strong> successfully created!"
br />$msg .= 
<br /><a href="
/administrator/'edit_album.php?album_id=">Click here</a> to administrate the " . $_POST['album_name'] . " album"; 
<br />$msg .= " </p>
<p><a href="/administrator/'
index.php'">Click here</a> to return to the administrative area</p>"; 
<br />displayPage($msg, "Album " . $_POST['
album_name'] . "Added!"); 
<br />} 
<br />

<p> </p>"; displayPage($msg, "Album " . $_POST['
album_name'] . "Added!"); } 

"Album " . $_POST['
album_name'] . "Added!");}

s a breakdown of the code:</p>
br />// Verify that all form elements are completed 
<br />if (empty($_POST['album_name']) || empty($_POST['album_desc'])){ 
br />displayPage("Please complete all required fields! 
<br /><a href="
/administrator/'new_album.php'">Go Back</a>""Error Adding Album!"); 
br />die(); 
br />}</p>

The include line, again, is to make use of the global variables and function that allow us to connect to the database.


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates


Dev Shed Tutorial Topics: