Multiple Image Upload with Update

I would like to offer my client the option of a form to upload stock to the database with 4 images.

I have found plenty of scripts to do this, but the other part I need is for my client to be able to go back to that stock item and if needed change all of the images, or maybe just one of the four if needed.

Can somebody point me to a good understandable tutorial, or if they maybe have a script to handy to paste back.

The form I currently have is that the form is empty once in the page ready to add stock to the database, and then on the same page they can select an item to edit any part of the stock, and I need to have the option of being able to edit the images, and if one isnt changed it keeps the image that is currently in the database.

Thanks

Have you implemented the initial upload part yet? There are plenty of ways to do this so it is a lot easier to suggest something if we know how you’re doing it partly. That said, if you haven’t and want to get a good idea, I’d definitely suggest finding some open source software that does it how you like and checking out the code, or even just letting readers of this post know so they can advise on how that’s achieved.

Yes I’ve done the initial upload and will post up the code next.


$path="";

if(isset($_GET['stock_Id']))
{
$q=mysql_query("select * from stock where stock_Id=$stock_Id") or die (mysql_error());	
$rows=mysql_fetch_assoc($q);
$path=$rows["stock_Image"];
}

if(isset($_POST['btndelete']))
{
$sr=$_POST['srno1'];
$flag=$_POST['flag'];
if ($flag==0)
{		
$q23=mysql_query("delete from stock where stock_Id=$sr") or die (mysql_error());
$flag=1;
}
else
{		
}
}

if(isset($_POST['btnsubmit']))
{
$src=$_FILES['logo']['tmp_name'];
$fname=$_FILES['logo']['name'];
$fname2=$_POST['logoCurrent'];
$src2=$_POST['logoCurrent'];

$path=$_POST['logoCurrent'];

if($_FILES['logo']['name']=="") {
copy("$src","$fname2");
$q24=mysql_query("update stock set stock_Image='$fname2' where stock_Id=$sr") or die (mysql_error());
} else {
copy("$src","imgdata/stock/$fname");
$q24=mysql_query("update stock set stock_Image='imgdata/stock/$fname' where stock_Id=$sr") or die (mysql_error());
$flag=1;
}
}
else
{
$path=$_FILES['logo']['name'];
								
copy("$src","imgdata/stock/$fname");
$q=mysql_query("insert into stock (stock_Image) values('imgdata/stock/$fname')") or die (mysql_error());	
$update=1;
}
}


<form name="form1" action="admin_stock.php?index=<?=$index?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="flag" value="<?= $flag?>">

<?
if(isset($_GET['stock_Id']))
{
?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Current Stock Image:</div>
</td>
<td bgcolor="#888888" width="713">
<div style="float:left; width:330px;"><input type="text" name="logoCurrent" size="80" value="<? echo $path;?>" /></div>
<div align="center" style="float:right; width:100px; margin-right:90px;">
<div id="thumbnail">
<a href="<? echo $path;?>" alt="hills" rel="Click Image To Close"><img src="images/view_Hotel_Button.jpg" width="100" height="20" rel="Click image to close." title="Click here to view this image"></a>
<p id="large"></p>
</div>

</div>
</td>
</tr>
<? } ?>	
<?
if(isset($_POST['btnsubmit']))
{
?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Current Stock Image:</div>
</td>
<td bgcolor="#888888" width="713">
<input type="text" name="logoCurrent" size="84" value="<? echo $path;?>" />&nbsp;<input type="button" value="View Image" onClick="javascript:popUp('viewImage.htm')" size="30">
</td>
</tr>
<? } ?>		
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">New Stock Image:</div>
</td>
<td bgcolor="#888888" width="713"><input type="file" name="logo" size="84" value="<? echo $path;?>" /></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Active:</div>
</td>

This seems to work fine, as its only the one image, but I have tried to get it to work with 4 images and I dont seem to be able to work it through.

Thanks for looking

This is a script i use… Super basic skeleton snippit i created years ago. I use this script in alot of my applications



<?

set_time_limit(300);
  $numoffile = 1;  // Set how many file uploads you want.


  if ($_POST) {  
    for ($i=0;$i<$numoffile;$i++) {  
      if (trim($_FILES['myfiles']['name'][$i])!="") {  
		$temp_file_location = $_FILES['myfiles']['tmp_name'][$i];
		$old_upload_file = $_FILES['myfiles']['name'][$i];
//        $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
        $newfile = $file_dir. $product_name . ".jpg";
        $filemoved = move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], "upload/$old_upload_file");
	
                   // run any command here after every file upload. 


        $j++;  
      }  
    }  
  }  
  if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";  
  print "<form method='post' enctype='multipart/form-data'>";  
  for($i=0;$i<$numoffile;$i++) {  
    print "<input type='file' name='myfiles[]' size='30'><br>";  
  }  
  print "<input type='submit' name='action' value='Upload'>";  
  print "</form>";  
  
?>



I have a stupid question… why are you string escaping VARIABLES?

copy(“$src”,“$fname2”);

Most odd. There’s NO reason for those double quotes to be there apart from making the code take longer to execute.

Hi Shaydez,

That looks good and very complicated.

If you could spare me a bit more info I would be very grateful so I can get my bearings.

Can you put the html to it, so that I can see how you put it all together.

Cheers

I’m looking at Shaydez code above and it looks great as far as I can tell as a novice, but what I cant work out is how would the form look to get this working, and how do I connect that code to my database to allow me to upload the image path to the table, so I can retrieve it on the web page.

This is a step up, as you can tell from my work, so if anyone can help me create the full workings from the form, to the image upload script to then pushing the images into the database that would be great.

I am going to make a start this morning, and see if I can figue it out.

Cheers

Hi, OK I can see how that code by Shaydez works, and have set it so the client has up to 4 images they can upload.

It might be a bit too much but I have pasted the full page below, and beneath that I have posted the code by shaydez and my bit and where I will need some help.


<?php
include "config.php";
include "header2.php";

$flag=1;

$name="";
$meta="";
$ref="";
$desc="";
$maker="";
$date="";
$weight="";
$height="";
$depth="";
$width="";
$price="";
$sold="";
//$path="";
//$path2="";
$conf ="";
$update="";
$pcats="";
$subcats="";
$dt2=date("Y-m-d H:i:s");

if(isset($_GET['stock_Id']))
{
	$stock_Id=$_GET['stock_Id'];
	$q=mysql_query("select * from stock where stock_Id=$stock_Id") or die (mysql_error());	
	$rows=mysql_fetch_assoc($q);
	$name=$rows["stock_Name"];
	$meta=$rows["stock_MetaTitle"];
	$pcats=$rows["parent_Category"];
	$subcats=$rows["sub_Category"];
	//$path=$rows["stock_Image"];
	//$path2=$rows["stock_Image2"];
	$ref=$rows["stock_Ref"];
	$desc=$rows["stock_Description"];
	$maker=$rows["stock_Maker"];
	$date=$rows["stock_Date"];
	$weight=$rows["stock_Weight"];
	$height=$rows["stock_Height"];
	$depth=$rows["stock_Depth"];
	$width=$rows["stock_Width"];
	$price=$rows["stock_Price"];
	$sold=$rows["stock_Sold"];
	$active=$rows["stock_Active"];
	$time=$rows["stock_DateTime"];
	$flag=0;
}

if(isset($_POST['btndelete']))
{
	$sr=$_POST['srno1'];
	$flag=$_POST['flag'];
	if ($flag==0)
	{		
	$q23=mysql_query("delete from stock where stock_Id=$sr") or die (mysql_error());
	$flag=1;
	}
	else
	{		
	}
}

if(isset($_POST['btnsubmit']))
{

$flag=$_POST['flag'];
if ($flag==0)
{
	
$name=$_POST['txtname'];
$desc1=$_POST['e1m1'];	

//$src=$_FILES['logo']['tmp_name'];
//$fname=$_FILES['logo']['name'];
//$fname2=$_POST['logoCurrent'];
//$src2=$_POST['logoCurrent'];
	
$meta=$_POST['txtmeta'];
$sr=$_POST['srno1'];
$name=$_POST['txtname'];
$ref=$_POST['Ref'];
$desc=$_POST['e1m1'];
$maker=$_POST['Maker'];
$date=$_POST['Date'];
$weight=$_POST['Weight'];
$height=$_POST['Height'];
$depth=$_POST['Depth'];
$width=$_POST['Width'];
$price=$_POST['txtprice'];
$sold=$_POST['txtsold'];
//$path=$_POST['logoCurrent'];
$active=$_POST['active'];
$pcats=$_POST['pcats'];
$subcats=$_POST['subcats'];

//if($_FILES['logo']['name']=="") {
//copy("$src","$fname2");
//copy("$srcb","$fname2b");
$q24=mysql_query("update stock set stock_Name='$name', stock_MetaTitle='$meta', parent_Category='$pcats', sub_Category='$subcats', stock_Ref='$ref', stock_Description='$desc1', stock_Maker='$maker', stock_Date='$date', stock_Weight='$weight', stock_Height='$height', stock_Depth='$depth',stock_Width='$width', stock_Price='$price', stock_Sold='$sold', stock_Active='$active', stock_DateTime='$dt2' where stock_Id=$sr") or die (mysql_error());
$flag=1;
$conf="Data Updated Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_categories.php'>here</a> to continue";
$update="1";
//} else {
//copy("$src","imgdata/stock/$fname");
//$q24=mysql_query("update stock set stock_Name='$name', stock_MetaTitle='$meta', parent_Category='$pcats', sub_Category='$subcats', stock_Image='imgdata/stock/$fname', stock_Ref='$ref', stock_Description='$desc1', stock_Maker='$maker', stock_Date='$date', stock_Weight='$weight', stock_Height='$height', stock_Depth='$depth',stock_Width='$width', stock_Price='$price', stock_Sold='$sold', stock_Active='$active', stock_DateTime='$dt2' where stock_Id=$sr") or die (mysql_error());
//$flag=1;
//$conf="Data Updated Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_categories.php'>here</a> to continue";
//$update="1";
//}
}
else
{
$name=$_POST['txtname'];
$ref=$_POST['Ref'];
$desc=$_POST['e1m1'];
$maker=$_POST['Maker'];
$date=$_POST['Date'];
$weight=$_POST['Weight'];
$height=$_POST['Height'];
$depth=$_POST['Depth'];
$width=$_POST['Width'];
$price=$_POST['txtprice'];
$sold=$_POST['txtsold'];	
//$src=$_FILES['logo']['tmp_name'];
//$fname=$_FILES['logo']['name'];
$meta=$_POST['txtmeta'];
//$path=$_FILES['logo']['name'];
$active=$_POST['active'];
$pcats=$_POST['pcats'];
$subcats=$_POST['subcats'];
								
//copy("$src","imgdata/stock/$fname");
$q=mysql_query("insert into stock (stock_Name, stock_MetaTitle, parent_Category, sub_Category, stock_Ref, stock_Description, stock_Maker, stock_Date, stock_Weight, stock_Height, stock_Depth, stock_Width, stock_Price, stock_Sold, stock_Active, stock_DateTime) values('$name','$meta','$pcats','$subcats','$ref','$desc','$maker','$date','$weight','$height','$depth','$width','$price','$sold','$active','$dt2')") or die (mysql_error());	
$conf="Data Inserted Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_stock.php'>here</a> to continue";
$update=1;
}
}

?>
<script language="javascript" type="text/javascript">
function check()
{
flg=confirm("Data would be permanently deleted, Are you sure?");
if(flg==true)
{
return true;	     	
alert("Record Deleted");
}	
else
{
return false;
}
}
</script>

<!-- TinyMCE -->
<script type="text/javascript" src="./jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		editor_selector : "mceEditor",
        editor_deselector : "mceNoEditor",

		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "./css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "./lists/template_list.js",
		external_link_list_url : "./lists/link_list.js",
		external_image_list_url : "./lists/image_list.js",
		media_external_list_url : "./lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->

<html>
<head>
<title>Sovereign Antiques Stock Management</title>
<link href="admin.css" rel="stylesheet" type="text/css" />

<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=700,left = 420,top = 100');");
}
</script>
<!-- Added last night -->
<script type="text/javascript" src="jquery-1.4.min.js"></script>
<script type="text/javascript" language="javascript">
	jQuery.fn.center = function () {
		this.css("position","absolute");
		this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
		this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
		return this;
	}

	$(document).ready(function() {		
		$("#thumbnail img").click(function(e){
		
			$("#background").css({"opacity" : "0.7"})
							.fadeIn("slow");			
						
			$("#large").html("<img src='"+$(this).parent().attr("href")+"' alt='"+$(this).attr("alt")+"' /><br/>"+$(this).attr("rel")+"")
					   .center()
					   .fadeIn("slow");			
			
			return false;
		});
			
		$(document).keypress(function(e){
			if(e.keyCode==27){
				$("#background").fadeOut("slow");
				$("#large").fadeOut("slow");
			}
		});
		
		$("#background").click(function(){
			$("#background").fadeOut("slow");
			$("#large").fadeOut("slow");
		});
		
		$("#large").click(function(){
			$("#background").fadeOut("slow");
			$("#large").fadeOut("slow");
		});
		
	});
</script>
</head>
<a name="Top"></a>
<body style="z-index:1;">
<div id="large"></div>
<div id="background"></div>
<form name="form1" action="admin_stock.php?index=<?=$index?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="flag" value="<?= $flag?>">
<table align="center">
<tr>
<div style="position:relative; height:90px; width:896px; background-color:#293334; margin-bottom:0px; margin-left:auto; margin-right:auto;">
<div style="position:relative; height:55px; width:100%; font-size:20px; color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; margin-left:25px; top:9px; font-weight:bold;">Sovereign Antiques 'Stock' Management Section</div>
<div style="position:relative; height:15px; width:100%;">
<div style="position:relative; float:left; margin-left:25px;">
<a href="main.php" class="topNav" title="Home">Home</a> <span style="color:#FFFFFF">|</span> <a href="index-logOut.php" class="topNav" title="Log Out">Log Out</a> <span style="color:#FFFFFF">|</span> <a href="http://www.accendsandbox.co.uk" target="_blank" class="topNav" title="Log Out">View Website</a> <span style="color:#FFFFFF">|</span>
</div>
</div>
</div>
</tr>
<!--<tr class="f1">
<td class="f1"><?= $conf ?></td>
</tr>-->
</table>
<table align="center" width="900" border="0" cellpadding="5" cellspacing="2">
<tr>
<td colspan="2" bgcolor="#222222" height="45" style="background-image:url(images/admin_Grey_Bar_Pages.jpg)">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:13px; color:#ffffff; font-weight:bold; position:relative; float:left; left:20px; top:-2px;">Create/Edit - 'Stock'</div>
</td>
</tr>

<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Title:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="txtname" size="84" value="<? echo $name;?>" /></td>
</tr>

<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Meta-Title:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="txtmeta" size="84" value="<? echo $meta;?>" /></td>
</tr>

<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Associated With:</div>
</td>
<td bgcolor="#888888" width="713">
<select name="pcats" size="1">
<option value="">Select Category</option>
<?php $qw=mysql_query("select cat_Id, category_Name from category order by category_Name ASC") or die (mysql_error());
while($r=mysql_fetch_assoc($qw))
	{
if($r['cat_Id']==$pcats)
	{
echo "<option value='$r[cat_Id]' selected>$r[category_Name]</option>";
	}
else
	{
echo "<option value='$r[cat_Id]'>$r[category_Name]</option>";
	}
}
?>
</select>
&nbsp; or &nbsp;
<select name="subcats" size="1">
<option value="">Select Sub-Category</option>
<?php $qw=mysql_query("select sub_Id, sub_Name from sub_category order by sub_Name ASC") or die (mysql_error());
while($r=mysql_fetch_assoc($qw))
	{
if($r['sub_Id']==$subcats)
	{
echo "<option value='$r[sub_Id]' selected>$r[sub_Name]</option>";
	}
else
	{
echo "<option value='$r[sub_Id]'>$r[sub_Name]</option>";
	}
}
?>
</select>
</td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Reference Number:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Ref" size="25" value="<? echo $ref;?>" /></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Description:</div>
</td>
<td bgcolor="#888888" width="713"><textarea id="e1m1" name="e1m1" rows="25" cols="80" style="width:100%" class="mceEditor"><? echo $desc;?></textarea></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Maker:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Maker" size="84" value="<? echo $maker;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Date:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Maker" size="24" value="<? echo $date;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Weight:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Weight" size="24" value="<? echo $weight;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Height:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Height" size="24" value="<? echo $height;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Depth:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Depth" size="24" value="<? echo $depth;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Width:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="Width" size="24" value="<? echo $width;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">* Optional</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Price:</div>
</td>				
<td bgcolor="#888888" width="713"><input type="text" name="txtprice" size="24" value="<? echo $price;?>" /> <span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;">(eg 1500 - No need for '£')</span></td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Sold or For Sale:</div>
</td>
<td bgcolor="#888888" width="713">
<select name="txtsold" size="1">
<?php
if($sold==1)
{
echo "<option value='1' selected>Sold</option>";
echo "<option value='0'>For Sale</option>";							
}
else
{
echo "<option value='1' >Sold</option>";
echo "<option value='0' selected>For Sale</option>";							
}
?>
</select>
</td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Images:</div>
</td>
<td bgcolor="#888888">
<?

set_time_limit(300);
  $numoffile = 4;  // Set how many file uploads you want.


  if ($_POST) {
    for ($i=0;$i<$numoffile;$i++) {
      if (trim($_FILES['myfiles']['name'][$i])!="") {
		$temp_file_location = $_FILES['myfiles']['tmp_name'][$i];
		$old_upload_file = $_FILES['myfiles']['name'][$i];
//        $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
        $newfile = $file_dir. $product_name . ".jpg";
        $filemoved = move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], "upload/$old_upload_file");

                   // run any command here after every file upload.
$q24=mysql_query("update stock set stock_Image='x', stock_Image2='x', stock_Image3='x', stock_Image4='x' where stock_Id=$sr") or die (mysql_error());

        $j++;
      }
    }
  }
  if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
  //print $newfile;
  //print "<form method='post' enctype='multipart/form-data'>";
  for($i=0;$i<$numoffile;$i++) {
    print "<input type='file' name='myfiles[]' size='70'><br>";
  }
  //print "<input type='submit' name='action' value='Upload'>";
  //print "</form>";

?>
</td>
</tr>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Active:</div>
</td>
<td bgcolor="#888888" width="713">
<select name="active" size="1">
<?php
if($active==1)
{
echo "<option value='1' selected>Active</option>";
echo "<option value='0'>Inactive</option>";							
}
else
{
echo "<option value='1' >Active</option>";
echo "<option value='0' selected>Inactive</option>";							
}
?>
</select>
</td>
</tr>

<tr>
<td bgcolor="#A0B050" width="161"><br></td>
<td bgcolor="#888888" width="713">
<table width="75%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10%">
<input type="submit" name="btnsubmit" value="Submit">
<input type="submit" name="btndelete" value="Delete" onClick="return check();">
<input type="hidden" name="srno1" value="<?= $rows["stock_Id"];?>">
<input type="hidden" name="action" value="Upload">
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr>
<td valign="top" height="45" bgcolor="#eeeeee" width="161" style="background-image:url(images/admin_Grey_Bar_Smallest.jpg)">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:13px; color:#ffffff; font-weight:bold; position:relative; float:left; left:20px; top:7px;">Existing Stock</div>
</td>
<td bgcolor="#eeeeee" style="background-image:url(images/admin_Grey_Bar_509_No_Arrow.jpg)"><div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:13px; color:#777777; font-weight:normal; position:relative; float:left; left:20px; top:-2px; font-style:italic;">Select 'Existing Stock Name' below to edit or delete...</div></td>
</tr>	
<tr>
<td width="161" bgcolor="#A0B050" height="35">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:10px;">Stock Name</div></td>
<td width="713" bgcolor="#A0B050" height="35">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:10px;">Stock Description</div><div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:right; width:100px; right:10px">Last Updated</div></td>
</tr>
				
<?php
$q=mysql_query("select * from stock order by stock_Name ASC") or die (mysql_error());				
while($row=mysql_fetch_assoc($q))
{
echo "<tr>";
echo "<td bgcolor='#888888' width='161' valign='top'>";
echo "<p style='position:relative; left:9px;'><font size='2' color='#ffffff' face='Verdana,Arial,Helvetica,sans-serif'><a href='admin_stock.php?stock_Id=".$row["stock_Id"]."&index=".$index."' style='color:FFFFFF; font-weight:normal;'>".$row["stock_Name"]."</a></font></p>";
echo "</td>";
echo "<td bgcolor='#888888' width='713' valign='top'><div style='position:relative; float:left; width:550px;'><font size='2' color='#ffffff' face='Verdana,Arial,Helvetica,sans-serif' style='position:relative; left:9px;'>".substr($row['stock_Description'],0,61)."...</font></div><div style='position:relative; float:right; width:150px; right:-5px; border-left:#333333 dotted 1px; height:20px;'><font size='1' color='#ffffff' face='Verdana,Arial,Helvetica,sans-serif' style='position:relative; margin-left:10px;height:20px;top:3px;'>".$row["stock_DateTime"]."</font></div></td>";
echo "</tr>";
}				
?>
<tr>
<td>
<div style="position:relative; width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px">Return to <a href="#Top">TOP</a></div>
</td>
<tr>
</table>
</form>
</div>
<?
if($update==1)
{
?>
<div id="cover">
<div id="warning">
<p align="center" style="color:#000000; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; line-height:20px;">
Your database was successfully updated - click the button below to return to admin.<br/><br/>
<input type="button" onClick="javascript:location.href=('http://www.accendsandbox.co.uk/adminSallam/admin_stock.php');" value="Return to admin" />
<br/><br/>
or
<br/><br/>
Click <a href="main.php">here</a> to return to main menu.
</p>
</div>
</div>						
<? } else { ?>
<? } ?>

</body>
</html>

What I am trying to do below is upload each image to its specific field in the table ‘stock’

But I think it will only upload one image at a time, and this is the bit I need a bit of help with.


<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Images:</div>
</td>
<td bgcolor="#888888">
<?

set_time_limit(300);
  $numoffile = 4;  // Set how many file uploads you want.


  if ($_POST) {
    for ($i=0;$i<$numoffile;$i++) {
      if (trim($_FILES['myfiles']['name'][$i])!="") {
		$temp_file_location = $_FILES['myfiles']['tmp_name'][$i];
		$old_upload_file = $_FILES['myfiles']['name'][$i];
//        $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
        $newfile = $file_dir. $product_name . ".jpg";
        $filemoved = move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], "upload/$old_upload_file");

                   // run any command here after every file upload.
$q24=mysql_query("update stock set stock_Image='x', stock_Image2='x', stock_Image3='x', stock_Image4='x' where stock_Id=$sr") or die (mysql_error());

        $j++;
      }
    }
  }
  if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
  //print $newfile;
  //print "<form method='post' enctype='multipart/form-data'>";
  for($i=0;$i<$numoffile;$i++) {
    print "<input type='file' name='myfiles[]' size='70'><br>";
  }
  //print "<input type='submit' name='action' value='Upload'>";
  //print "</form>";

?>
</td>
</tr>

My bit is after:
// run any command here after every file upload.

OK I have moved forward with this slightly, but I’m stuck on the final bit.

Here is the part of the form that deals with the insert and update of images to the database.
There are four images


<? if(isset($_GET['stock_Id']))
{ ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 1 (Main):</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic[]" size="50" /> <input type="hidden" name="p1" value="<?php echo $pic1;?>" /> &nbsp;<img src="<?php echo $pic1;?>" height="100px" />
</td>
</tr>
<? } else { ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 1 (Main):</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic1[]" id="pic1[]" size="50" />
</td>
</tr>
<? } ?>

<? if(isset($_GET['stock_Id']))
{ ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 2:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic[]" size="50" /> <input type="hidden" name="p2" value="<?php echo $pic2;?>" /> &nbsp;<img src="<?php echo $pic2;?>" height="100px" />
</td>
</tr>
<? } else { ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 2:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic1[]" id="pic1[]" size="50" />
</td>
</tr>
<? } ?>
<? if(isset($_GET['stock_Id']))
{ ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 3:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic[]" size="50" /> <input type="hidden" name="p3" value="<?php echo $pic3;?>" /> &nbsp;<img src="<?php echo $pic3;?>" height="100px" />
</td>
</tr>
<? } else { ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 3:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic1[]" id="pic1[]" size="50" />
</td>
</tr>
<? } ?>
<? if(isset($_GET['stock_Id']))
{ ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 4:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic[]" size="50" /> <input type="hidden" name="p4" value="<?php echo $pic4;?>" /> &nbsp;<img src="<?php echo $pic4;?>" height="100px" />
</td>
</tr>
<? } else { ?>
<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 4:</div>
</td>
<td bgcolor="#888888">
<input type="file" name="pic1[]" id="pic1[]" size="50" />
</td>
</tr>
<? } ?>

To upload to the database I am using the code below, and all is working fine.


$pic1='';
for($i=0;$i<4;$i++){
if(isset($_FILES['pic1']['name'][$i]))$pic1[$i]=$_FILES['pic1']['name'][$i];
else $pic1[$i]='';
}
for($i=0;$i<4;$i++){
if(isset($_FILES['pic1']['name'][$i]))$path1= "./imgdata/stock/".$_FILES['pic1']['name'][$i];
//echo $_FILES['pic1']['tmp_name'][$i]." :". $path1;
if(!empty($_FILES['pic1']['name'][$i])&&isset($_FILES['pic1']['name'][$i]))copy($_FILES['pic1']['tmp_name'][$i], $path1);
}
								
$q=mysql_query("insert into stock (stock_Name, stock_MetaTitle, parent_Category, sub_Category, stock_Ref, stock_Description, stock_Maker, stock_Date, stock_Weight, stock_Height, stock_Depth, stock_Width, stock_Price, stock_Sold, stock_Image, stock_Image2, stock_Image3, stock_Image4, stock_Active, stock_DateTime) values('$name','$meta','$pcats','$subcats','$ref','$desc','$maker','$date','$weight','$height','$depth','$width','$price','$sold','imgdata/stock/$pic1[0]','imgdata/stock/$pic1[1]','imgdata/stock/$pic1[2]','imgdata/stock/$pic1[3]','$active','$dt2')") or die (mysql_error());	
$conf="Data Inserted Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_stock.php'>here</a> to continue";
$update=1;
}
}

This is the bit that is relevant above


'imgdata/stock/$pic1[0]','imgdata/stock/$pic1[1]','imgdata/stock/$pic1[2]','imgdata/stock/$pic1[3]'

My problem is trying to update. I can get the new image to go to the server in the right folder, but its not allowing me to edit say one image and leave the others be, or edit all.


$str_str='';
    $p='';
    $j=0;
    for($i=0;$i<=3;$i++){
    $j++;
    $p=$_REQUEST['p$j'];
    $file=$_FILES['pic']['name'][$i];

    if(!empty($file) ){
              $str_str.=",pic$j='$file'";
     }
     else if(!empty($p))$str_str.=",pic$j='$p'";

     $path1="imgdata/stock/".$file;
     copy($_FILES['pic']['tmp_name'][$i], $path1);

    }

$q24=mysql_query("update stock set stock_Name='$name', stock_MetaTitle='$meta', parent_Category='$pcats', sub_Category='$subcats', stock_Ref='$ref', stock_Description='$desc1', stock_Maker='$maker', stock_Date='$date', stock_Weight='$weight', stock_Height='$height', stock_Depth='$depth',stock_Width='$width', stock_Price='$price', stock_Sold='$sold', stock_Image='imgdata/stock/$pic', stock_Image2='imgdata/stock/$pic', stock_Image3='imgdata/stock/$pic', stock_Image4='imgdata/stock/$pic', stock_Active='$active', stock_DateTime='$dt2' where stock_Id=$sr") or die (mysql_error());

The relevant bit.


stock_Image='imgdata/stock/$pic', stock_Image2='imgdata/stock/$pic', stock_Image3='imgdata/stock/$pic', stock_Image4='imgdata/stock/$pic',

I have tried $pic, also $pic[0] - $pic[3] and nothing seems to work, can anybody help me with this bit.

Hopefully I have included everything