I need to take the file name of each file here and write it to the database.
I've tried everything I can think of... now I need your help. Thanks, -Mike
There are three files. Instead of looping the script I just pasted it three times, and changed the uploadimage to uploadimage, uploadimage2, uploadimage3.
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO inventory VALUES ('','$catid','$brand','$description','$price','$intfree','$picurl1','$picurl2','$picurl3')";
mysql_query($query);
mysql_close();
// Where the file is going to be placed
$target_path = "images/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>";
} else{
echo "There was an error uploading the file, please try again!<br>";
}
// Where the file is going to be placed
$target_path = "images/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile2']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile2']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile2']['name']). " has been uploaded<br>";
} else{
echo "There was an error uploading the file, please try again!<br>";
}
// Where the file is going to be placed
$target_path = "images/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile3']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile3']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile3']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile3']['name']). " has been uploaded<br>";
} else{
echo "There was an error uploading the file, please try again!<br>";
}
Are the files getting uploaded correctly? If not, are your CHMOD correct for the spicified folder, 'images/', I belive they should be 0777
Is the database getting updated?
Hmm, which values within the SQL statement are designed to be the filenames?
I'm guessing its $picurl1, $picurl2, $picurl3? If so, these are the only variables that aren't getting set prior to the SQL statement taking place.
PHP Code:
$catid=$_POST['catid'];
$brand=$_POST['brand'];
$description=$_POST['description'];
$price=$_POST['price'];
$intfree=$_POST['intfree'];
// Set the pic url variables
$picurl1=$_FILES['uploadedfile']['name'];
$picurl2=$_FILES['uploadedfile2']['name'];
$picurl2=$_FILES['uploadedfile3']['name'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO inventory VALUES ('','$catid','$brand','$description','$price','$in tfree','$picurl1','$picurl2','$picurl3')";
mysql_query($query);
mysql_close();
I would also recommend executing the SQL statement after the files have been uploaded without any errors, otherwise you might get a few odd records that are missing files.