How do i do this..?
Posted: Mon Feb 16, 2004 5:32 pm
Ok i have a form that takes in data and puts it in mysql. This form also uploads 2 files. How would i get the name of the files that people upload into mysql columns? ('imagefile' and 'mp3file'.) Heres what i tried: (imagefile and mp3file columns were blank when i checked in phpmyadmin)
Code: Select all
<?
//MySQL Variables
$host = "hostname";
$login_name = "username";
$password = "password";
//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 = $_POSTї'imagefile']ї'name'];
$mp3file = $_POSTї'mp3file']ї'name'];
//This is the File upload part
$uploaddir = $_SERVERї'DOCUMENT_ROOT'].'/localmm/upload/';
$uploadfile1 = $uploaddir . $_FILESї'imagefile']ї'name'];
$uploadfile2 = $uploaddir . $_FILESї'mp3file']ї'name'];
if (!move_uploaded_file($_FILESї'imagefile']ї'tmp_name'], $uploadfile1)) {
print "ERROR: File is invalid";
print_r($_FILES);
}
if (!move_uploaded_file($_FILESї'mp3file']ї'tmp_name'], $uploadfile2)) {
print "ERROR: File is invalid";
print_r($_FILES);
}
$sql = "INSERT INTO nuke_bands (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) {
header("Location: http://naild.com/localmm/modules.php?name=Band_List&file=sent");
} else {
echo("An error has occured");
}
MySQL_close()
?>