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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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:

 
<p><!--p<-->include_once("../include/config.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!"); } 

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

 
<p>Here'
s a breakdown of the code:</p>
<
p>include_once("../include/config.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 />}</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
   

MYSQL ARTICLES

- Xeround Releases Free Version of MySQL Cloud...
- Oracle Announces New MySQL Specialization
- Constant Contact Chooses SkySQL for MySQL Su...
- Revoke Statement in MySQL
- The Grant Statement in MySQL
- SuccessBricks Announces ClearDB Availability...
- Building a PHP ORM: Deploying a Blog
- TROSYS Launches Free MySQL Manager and Admin...
- Building an ORM in PHP: Domain Modeling
- Building an ORM in PHP
- MySQL Leads Open Source Market, Gets Cluster...
- Oracle Announces Milestone Release for MySQL
- How to Stop SQL Injection Attacks
- New Defragmentation Solution for SQL Server
- Comparison of MyISAM and InnoDB MySQL Databa...


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap

Dev Shed Tutorial Topics: