www.webdeveloper.com
Results 1 to 3 of 3

Thread: Adding photo name to database

  1. #1
    Join Date
    Feb 2011
    Posts
    177

    Question Adding photo name to database

    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.

    file Upload Images
    HTML Code:
    <form name="form1" method="post" action="upload.php">
    <SELECT NAME=albumname>
        <OPTION VALUE=0>Choose
          <?=$options?>
        </SELECT>
      <p>
        <input type="file" name="fileField" id="fileField" />
      </p>
      <p>
        <input type="file" name="fileField2" id="fileField2" />
    </p>
      <p>
        <input type="file" name="fileField3" id="fileField3" />
    </p>
      <p>
        <input type="file" name="fileField4" id="fileField4" />
    </p>
      <p>
        <input type="file" name="fileField5" id="fileField5" />
    </p>
      <p>
        <input type="file" name="fileField6" id="fileField6" />
    </p>
      <p>
        <input type="file" name="fileField7" id="fileField7" />
    </p>
      <p>
        <input type="file" name="fileField8" id="fileField8" />
    </p>
      <p>
        <input type="file" name="fileField9" id="fileField9" />
    </p>
      <p>
        <input type="file" name="fileField10" id="fileField10" />
    </p>
      <p>
        <input type="submit" name="button" id="button" value="Submit">
      </p>
      <p>&nbsp;</p>
    </form>
    upload.php File
    PHP Code:
    <?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();
    }
    ?>

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    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.

  3. #3
    Join Date
    Feb 2011
    Posts
    177

    Question 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
    PHP Code:
        move_uploaded_file$_FILES['fileField']['tmp_name'], "American Legion Photos/$albumname/$newname"); 
    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();
    }
    ?>
    Here is the form page
    HTML Code:
    <form name="form1" method="post" action="upload.php">
    <SELECT NAME=options>
        <OPTION VALUE=0>Choose
          <?=$options?>
        </SELECT>
      <p>
        <input type="file" name="fileField" id="fileField" />
      </p>
    
        <input type="submit" name="button" id="button" value="Submit">
      </p>
      <p>&nbsp;</p>
    </form>
    Any and all help is much appreciated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles