Here is my code: (it might be a little sloppy, but i had some help so it should be fine)
Validation:
<?php
// Purpose: Validate and then insert Sermon data from an easy to
use web form
// database connection scripts
// Connection Variables
$dbhost = 'localhost';
$dbusername = '*****';
$dbpasswd = '*****';
$database_name = 'timothy';
// Connection
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection) or die
("Couldn't select database.");
//Output Buffering
ob_start();
// First things, first. Anywhere your using session data, you
need a Session Start!
session_start();
session_unset('errors'); // this unsets the errors, if the user
fixed it, we don't want them fixing it agian!
//Get Post vars into an array
$sermon = $_POST;
// Make the $sermon array variable into a session variable, so
that it can be used incase of a users error!
$_SESSION['sermon'] = $sermon;
// Create a SESSION error variable so that we can report any
errors to the user.
$_SESSION['errors'] = $errors;
// Validation
if ((empty($sermon['title'])) || (empty($sermon['scripture']))
|| (empty($sermon['month'])) || (empty($sermon ['day'])) || (empty
($sermon['year'])) || (empty($sermon['time'])) || (empty($sermon
['preacher'])) || (empty($sermon ['church'])) || (empty($sermon
['service'])) || (empty($sermon['weekday'])) || (empty($sermon
['sermon']))){
$errors['mistake'] = "<b>You Leftout the following required
information, Please fill them out now. If Unknown, please put
N/A,</b>";
if (empty($sermon['title']))
$errors['title'] = "Please Select a <b>Title</b> for the
Sermon.<br>";
if (empty($sermon['scripture']))
$errors['scripture'] = "Please Provide a <b>Scripture</b>
for the Sermon.<br>";
if (empty($sermon['month']))
$errors['month'] = "Please Provide a <b>Month</b> for the
Date.<br>";
if (empty($sermon['day']))
$errors['day'] = "Please Provide a <b>Day</b> for the
Date.<br>";
if (empty($sermon['year']))
$errors['year'] = "Please Provide a <b>Year</b> for the
Date.<br>";
if (empty($sermon['time']))
$errors['time'] = "Please Select AM or PM for the
<b>Time</b> of the Sermon.<br>";
if (empty($sermon['preacher']))
$errors['preacher'] = "Please Provide the Name of the
<b>Preacher</b> of the Sermon.<br>";
if (empty($sermon['church']))
$errors['church'] = "Please Provide the Name of the
<b>Church</b> Where the Sermon was Preached.<br>";
if (empty($sermon['service']))
$errors['service'] = "Please provide the <b>Service</b>
During Which the Message was Preached.<br>";
if (empty($sermon['weekday']))
$errors['weekday'] = "Please provide the <b>Day of the
Week</b> That the Sermon was Preached.<br>";
if (empty($sermon['sermon']))
$errors['sermon'] = "Please provide the <b>Sermon
File</b> of the Sermon.<br>";
}
// Prepare and simplify variables to create a sermon file name.
$title_trimmed = trim($sermon['title'], 15);
$title_date = $sermon['month'] . $sermon['day'] . $sermon
['year'];
$title_preacher = $sermon['preacher'];
$filename = $title_trimmed . $title_date . $title_preacher;
$remove = array(" ", "/"); // these are the characters we want to
remove from the filename.
$filename = str_replace($remove, "", $filename);
// Set the Web and Server paths.
$webpath =
"http://www.tacitwebsolutions.com/timothy/sermonhost/"; // Web
Address to Sermon Directory
$dirToSaveIn = "/home/tacitwebsolutions/www/timothy/sermonhost";
// Server Path to Sermon Directory
// Error Count
if (count($errors) > 0){
header("Location: sermonform.php");
exit;
}
// Upload Sermon
if (!empty($_FILES['sermon']['type'])){
$extension = "";
if($_FILES['sermon']['type'] == "audio/x-ms-wma"){ $extension
= "wma"; }
elseif($_FILES['sermon']['type'] == "audio/x-pn-realaudio"){
$extension = "ra"; }
elseif($_FILES['sermon']['type'] == "audio/mpeg"){ $extension
= "mp3"; }
else{
$errors['sermon'] = "Your file is not a supported format.
Please upload .wma, .mp3, and .ra files only!";
}
$filename = $filename . "." . $extension;
$serverpath = $dirToSaveIn . "/" . $filename;
//echo "filename: " . $filename . "<br>";
//echo "serverpath: " . $serverpath. "<br>";
$webpath = $webpath . $filename;
$move_result = move_uploaded_file($_FILES['sermon']
['tmp_name'], $serverpath);
}
// Error Count
if (count($errors) > 0){
header("Location: sermonform.php");
exit;
}
// Prepare webpath for Database
$webpath = addslashes($webpath);
// Create an acceptable mysql date for the date the sermon was
preached and the date it was entered into the database.
$date_preached = $sermon['year'] ."-". $sermon['month'] ."-".
$sermon['day'];
$date_entered = date('Y-m-d');
/* Check Data
echo "Title: " . $sermon['title'] . "<br>";
echo "Scripture: " . $sermon['scripture'] . "<br>";
echo "Date Preached: " . $date_preached . "<br>";
*/
// MySQL Insert Data
$query = "INSERT INTO sermonhost (title, scripture,
date_preached, time, preacher, church, service, weekday, sermon,
date_entered)
VALUES ('" .$sermon['title']."', '" .$sermon
['scripture']. "', '$date_preached',
'" .$sermon['time']. "', '" .$sermon
['preacher']. "', '" .$sermon['church']. "',
'" .$sermon['service']. "', '" .$sermon
['weekday']. "', '$webpath', '$date_entered')";
// Execute Query
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());
// Close the Mysql Database
mysql_close();
// Display Confirmation Message
echo "Information was successfully put into the database";
// Unset the Session Variables so that they will not interfear
with other processes.
session_unset($sermon); // $sermon may need to be changed to
$sermonForm, or somthing else... maybe.
?>