Code: Select all
<?
//MySQL Variables
$host = "host";
$login_name = "loginname";
$password = "pass";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");
//Select the database
MySQL_select_db("bandsandmembers") or die("Could not select database");
//Assign contents of form to variables
$bandname = $_POST['band_name'];
$description = $_POST['description'];
$history = $_POST['history'];
$influences = $_POST['influences'];
$genra = $_POST['genra'];
$email = $_POST['email'];
$website = $_POST['website'];
$imagefile = $_FILES['imagefile']['name'];
$mp3file = $_FILES['mp3file']['name'];
$types = array("image/gif","image/jpeg","image/bmp","image/pjpeg","image/x-windows-bmp");
$types2 = array("audio/mpeg","audio/mp3","audio/x-mpeg-3","audio/x-mp3","audio/m3u","audio/x-m3u","application/x-compressed","application/zip","multipart/x-zip","application/x-troff-msvideo","video/msvideo","video/x-msvideo","application/x-compressed","video/avi","video/mpeg","audio/mpeg3","video/mpeg","video/x-mpeg");
//This is the File upload part
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/localmm/upload/';
$uploadfile1 = $uploaddir . $_FILES['imagefile']['name'];
$uploadfile2 = $uploaddir . $_FILES['mp3file']['name'];
//Check to see weather there is a file in our upload folder with the same name
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'.$imagefile)) {
echo "There is already a file called <b>$imagefile</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
exit();
}
//Check to see weather there is a file in our upload folder with the same name
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'.$mp3file)) {
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
exit();
}
if (in_array($_FILES['imagefile']['type'], $types)){
move_uploaded_file($_FILES['imagefile']['tmp_name'], $uploadfile1);
}else{
echo "There was an error when uploading. Your file could have been too big. or Check to see if you uploaded the correct file type. Allowd file types are. .gif, .jpg, .jpeg, .bmp";
}
if (in_array($_FILES['mp3file']['type'], $types2)){
move_uploaded_file($_FILES['mp3file']['tmp_name'], $uploadfile2);
}else{
echo "There was an error when uploading. Your file could have been too big. or Check to see if you uploaded the correct file type. Allowd file types are. .mp3, .avi, .mpg, .mpeg, .zip";
}
$sql = "INSERT INTO $genra (band_name, description, history, influences, genra, email, website, imagefile, mp3file) VALUES ('$bandname','$description','$history','$influences','$genra','$email','$website','$imagefile','$mp3file')";
$result = mysql_query($sql);
//Code to check if statement executed properly and display message
if ($result) {
} else {
echo("An error has occured");
}
//Close connection with MySQL
MySQL_close()
?>
?>