<?php
include("epkheader.inc");
// read in the connection settings
require("dbconnection.txt");
// connect to the RDBMS
$db = mysql_connect("$site","$user","$pass")
or die_now("<h2>Could not connect to database server</h2><p>Check passwords and sockets</p>");
// select the database
mysql_select_db("$database",$db)
or die_now("<h2>Could not select database $database</h2><p>Check database name</p>");
function do_upload() {
// Create an array containing all valid upload file types for this script
$allowed_types = array(
"image/gif" => "gif",
"image/pjpeg" => "pjpg",
"image/jpeg" => "jpeg",
"image/png" => "png",
"image/tif" => "tif",
"image/tiff" => "tiff",
"image/bmp" => "bmp",
// Add more types here if you like
);
// Check to see if the file type is in the allowed types array
if(!array_key_exists($_FILES['userfile']['type'], $allowed_types))
if(!array_key_exists($_FILES['userfile2']['type'], $allowed_types)) {
die("Invalid file type.");
}
// Set the maximum uploadable file size => 51200 = 50kb
$maxfilesize = 2008204800;
// Is the file larger than it is allowed to be?
if($_FILES['userfile']['size'] > $maxfilesize)
if($_FILES['userfile2']['size'] > $maxfilesize){
die("Total Files too large in size. Please reduce the file size and try again.");
}
// Where will the file be uploaded to?
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/bschedule/bsadmin/bandpic/";
$uploaddir2 = $_SERVER['DOCUMENT_ROOT'] . "/bschedule/bsadmin/bandpic/";
// What is the files temporary name?
$file = $_FILES['userfile']['tmp_name'];
$file2 = $_FILES['userfile2']['tmp_name'];
// What is the files actual name?
$filename = $_FILES['userfile']['name'];
$filename2 = $_FILES['userfile2']['name'];
{
// Copy the file.
copy($file, $uploaddir.$filename) and copy($file2, $uploaddir2.$filename2) or
copy($file, $uploaddir.$filename) or copy($file2, $uploaddir2.$filename2) or
die("Could not list your image");
}
$getuid = $_POST['uid'];
$sqlQ = "UPDATE epk SET bandpic = '/bschedule/bsadmin/bandpic/".$filename."', bandlogo = '/bschedule/bsadmin/bandpic/".$filename2."' WHERE id = '".$_POST["id"]."';";
$sqlR = mysql_query($sqlQ)or die("Could not do a mysql query. Reason why: ".mysql_error());
}
// If the form has been completed, execute the upload function (above).
if($_POST['action'] == "do_upload") {
do_upload();
}
?>
What I need to do is make this so that if (on the previous page) one of the two fields are blank (if the user does not choose to upload anything) than the info in the database does not change. There is default info set into it.
If the user does choose to upload an image, then this will work, but if they decide to not upload them, or only upload one, then the fields they do not upload changes the info in the database and leaves the horrible red X.
So, I just want to make it so if one is blank, it is ignored in the database and the info in there is left alone... this will also be for the update page in case they only want to update one image instead of both.
Thanks a million for any help.
Peredy