I want to take the name of the photo that is being uploaded and save that name and the album location to the database. Here is what I have. Any help is much appreciated.
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Parse the form data and add inventory item to the system
include "../storescripts/connect_to_mysql.php";
if (isset($_POST['albumname'])) {
$albumname = mysql_real_escape_string($_POST['albumname']);
$photoname = mysql_real_escape_string($_POST['fileField']);
$photoname = mysql_real_escape_string($_POST['fileField2']);
$photoname = mysql_real_escape_string($_POST['fileField3']);
$photoname = mysql_real_escape_string($_POST['fileField4']);
$photoname = mysql_real_escape_string($_POST['fileField5']);
$photoname = mysql_real_escape_string($_POST['fileField6']);
$photoname = mysql_real_escape_string($_POST['fileField7']);
$photoname = mysql_real_escape_string($_POST['fileField8']);
$photoname = mysql_real_escape_string($_POST['fileField9']);
$photoname = mysql_real_escape_string($_POST['fileField10']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM AlbumPhotos WHERE albumname='$albumname' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 1) {
echo 'Sorry you tried to place a duplicate "Album Name" into the system, <a href="upload.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO AlbumPhotos (albumname, fileField, fileField2, fileField3, fileField4, fileField5, fileField6, fileField7, fileField8, fileField9, fileField10, date_added)
VALUES('$albumname','$fileField','$fileField2','$fileField3','$fileField4','$fileField5','$fileField6','$fileField7','$fileField8,'$fileField9','$fileField10',now())") or die (mysql_error());
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField2']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField3']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField4']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField5']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField6']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField7']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField8']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField9']['tmp_name'], "American Legion Photos/$albumname/$newname");
move_uploaded_file( $_FILES['fileField10']['tmp_name'], "American Legion Photos/$albumname/$newname");
header("location: upload.php");
exit();
}
?>
What if someone wants to make the album with eleven or more entries? I would recommend one table to store album names with a reference ID then have another table with photo names and the with a index number, album number and name columns, plus what any other information you want. That way it will be much more expandable.
Thanks, Not acually uploading Images to folder and keeps giving error
Hey, Thanks for the response. The reason they are in one database is because I need it to list the album names then when someone chooses an album then it will show those images. It has to know what images are in what album in order to do that. Hopefully that makes since.
I got it to upload to database like I want but now I have two other issues.
One it keeps giving me this error.
Notice: Undefined index: fileField in upload.php on line 25
this is that code
The other issue is that it is not actually loading the image into the folder I don't know why it is a 777 code so adding images should be good. Below is all the code I have.
PHP Code:
<?php
// Parse the form data and add inventory item to the system
include "Connection File Here";
if (isset($_POST['fileField'])) {
$albumname = mysql_real_escape_string($_POST['options']);
$photoname = mysql_real_escape_string($_POST['fileField']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM AlbumPhotos WHERE photoname='$photoname' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 1) {
echo 'Sorry you tried to place a duplicate "Photo Name" into the system, <a href="upload.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO AlbumPhotos (albumname, photoname, date_added)
VALUES('$albumname','$photoname',now())") or die (mysql_error());
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "American Legion Photos/$albumname/$newname");
exit();
}
?>
Bookmarks