Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-28-2012, 09:54 PM   PM User | #1
mathruD
New Coder

 
Join Date: Apr 2011
Posts: 45
Thanks: 6
Thanked 0 Times in 0 Posts
mathruD is an unknown quantity at this point
Problem with taking in an id when uploading multiple images

I recently bought the Advanced Multi Uploader extension for Dreamweaver. The extension works fine for uploading multiple images (when I'm only taking in an id and the image filename.

However, I have two tables in my database. One table, called album, takes in album_id and album_title. The other table, called photo, takes in a photo_id, photo_image, and album_id.

So what I want to do is create an add page for the photos. On that add page, I have created a recordset for album, as I want to pull album_id and album_title for a select menu. The select menu would then set the value for album_id, in the photo table. This typically works just fine, but for some reason when I use the multi upload extension it doesn't work.

The photo_add.php page takes in the multiple images with no problems. It stores them in the photo table and photo_id and photo_image are set for each. However, album_id keeps getting set to 0. It's like the select menu isn't setting the value as it is supposed to.

Can someone please help me figure out why it's doing this? I imagine it has to be something simple. I'm not a pro at php by any means so it has me stumped.

PHP Code:
<?php require_once('../Connections/xxxxxxx.php'); ?>
<?php 
require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
// Pure PHP Upload 2.1.12
$ppu = new pureFileUpload();
$ppu->path "../uploads";
$ppu->extensions "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName "UploadQueue";
$ppu->storeType "file";
$ppu->sizeLimit "";
$ppu->nameConflict "uniq";
$ppu->nameToLower false;
$ppu->requireUpload true;
$ppu->minWidth "";
$ppu->minHeight "";
$ppu->maxWidth "";
$ppu->maxHeight "";
$ppu->saveWidth "";
$ppu->saveHeight "";
$ppu->timeout "600";
$ppu->progressBar "";
$ppu->progressWidth "";
$ppu->progressHeight "";
$ppu->redirectURL "";
$ppu->checkVersion("2.1.12");
$ppu->doUpload();

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if (isset(
$editFormAction)) {
  if (isset(
$_SERVER['QUERY_STRING'])) {
      if (!
eregi("GP_upload=true"$_SERVER['QUERY_STRING'])) {
        
$editFormAction .= "&GP_upload=true";
        }
  } else {
    
$editFormAction .= "?GP_upload=true";
  }
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "UploadQueue")) {
  
$insertSQL sprintf("INSERT INTO photo (photo_image, album_id) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['Filedata'], "text"),
                       
GetSQLValueString($_POST['Filedata'], "int"));

  
mysql_select_db($database_RobeccaGandP$RobeccaGandP);
  
$Result1 mysql_query($insertSQL$RobeccaGandP) or die(mysql_error());
}

mysql_select_db($database_RobeccaGandP$RobeccaGandP);
$query_album_rs "SELECT album_id, album_title FROM album ORDER BY album_title ASC";
$album_rs mysql_query($query_album_rs$RobeccaGandP) or die(mysql_error());
$row_album_rs mysql_fetch_assoc($album_rs);
$totalRows_album_rs mysql_num_rows($album_rs);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script language='javascript' src='../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>

<body>

<form action="<?php echo $editFormAction?>" method="POST" enctype="multipart/form-data" name="UploadQueue" id="UploadQueue" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','');return document.MM_returnValue">
  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,63,0" width="550" height="350" id="upload1" align="middle">
    <param name="FlashVars" value="url=<?php echo urlencode($GP_uploadAction); ?>&formName=UploadQueue&FlashUpload=true<?php if ($ppu->redirectURL <> '') {echo "&redirectUrl=".$ppu->redirectURL;}?>" />
    <param name="movie" value="dmxMultiUploader.swf" />
    <param name="quality" value="best" />
    <param name="wmode" value="transparent" />
    <!--[if !IE]>-->
    <embed src="dmxMultiUploader.swf" name="upload1" quality="best" flashvars="url=<?php echo urlencode($GP_uploadAction); ?>&formName=UploadQueue&FlashUpload=true<?php if ($ppu->redirectURL <> '') {echo "&redirectUrl=".$ppu->redirectURL;}?>" wmode="transparent" type="application/x-shockwave-flash" width="550" height="350" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    <!--<![endif]-->
  </object>
  <input name="Filename" type="file" style="display:none" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','')" />
  
  
        
          <select name="album_id">
            <?php do { ?>
            <option value="<?php echo $row_album_rs['album_id']?>" ><?php echo $row_album_rs['album_title']?></option>
             <?php } while ($row_album_rs mysql_fetch_assoc($album_rs)); ?>
            </select>
         
          
          
          
<input type="hidden" name="Filedata" />
  <script type="text/javascript">window.upload1 = document.forms["UploadQueue"].upload1;</script>
  <input type="hidden" name="MM_insert" value="UploadQueue" />
</form>
</body>
</html>
<?php
mysql_free_result
($album_rs);
?>
mathruD is offline   Reply With Quote
Old 06-28-2012, 10:04 PM   PM User | #2
mathruD
New Coder

 
Join Date: Apr 2011
Posts: 45
Thanks: 6
Thanked 0 Times in 0 Posts
mathruD is an unknown quantity at this point
Also, I've included a few screenshots that may help. The first two are the tables for album and photo. You'll see that the album_id in photo keeps getting set to 0.

Also, there is a screenshot of the form in the browser. It's not styled or anything so ignore that. But you can see that the drop-down menu is there to set a value for the album_id in the photo table.



mathruD is offline   Reply With Quote
Old 06-28-2012, 11:09 PM   PM User | #3
mathruD
New Coder

 
Join Date: Apr 2011
Posts: 45
Thanks: 6
Thanked 0 Times in 0 Posts
mathruD is an unknown quantity at this point
Nevermind. I got it working by changing one word. In case anyone was wondering, it was in the following code:

PHP Code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "UploadQueue")) {
  
$insertSQL sprintf("INSERT INTO photo (photo_image, album_id) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['Filedata'], "text"),
                       
GetSQLValueString($_POST['Filedata'], "int"));

  
mysql_select_db($database_RobeccaGandP$RobeccaGandP);
  
$Result1 mysql_query($insertSQL$RobeccaGandP) or die(mysql_error());


All I did was change the word where I have inserted the comment:

PHP Code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "UploadQueue")) {
  
$insertSQL sprintf("INSERT INTO photo (photo_image, album_id) VALUES (%s, %s)",
                       
GetSQLValueString($_POST['Filedata'], "text"),
                       
GetSQLValueString($_POST['album_id'], "int"));          //changed this from Filedata to album_id

  
mysql_select_db($database_RobeccaGandP$RobeccaGandP);
  
$Result1 mysql_query($insertSQL$RobeccaGandP) or die(mysql_error());


Last edited by mathruD; 06-28-2012 at 11:11 PM..
mathruD is offline   Reply With Quote
Reply

Bookmarks

Tags
advanced multi uploader, database, image, multi, recordset

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:44 PM.


Advertisement
Log in to turn off these ads.