Page 1 of 1

Upload not setting Image Name... ah!

Posted: Wed Oct 12, 2005 1:46 pm
by $var
Grr....

I don't understand.
I am able to get as far as the copy command in this script, which is good...
But I cannot(!) make get the name of the image to write to the database.
It's pretty much the final piece of my project and it is super frustrating to be stuck on such a nit picky little piece.

The upload fields are titled 'imagefield1' and 'imagefield2'
But the value going to the database is defaulted at 'None'
The best I have been able to do it to make the 'None' in one of the fields turn to a 0, and it's not an INT field. :(

Can anyone help?

Code: Select all

$sql = "SELECT 
		Spk_ID, 
		Spk_FName, Spk_LName 
		FROM speaker WHERE 
		Spk_FName='".str_replace("'","'",$_POST["fname"])."' AND Spk_LName='".str_replace("'","'",$_POST["lname"])."'";
			if(!$result = mysql_query($sql))
			{
				echo mysql_error();
				echo "error on select";
			}
			$speakerresults = mysql_fetch_array($result);
			$speakerid = $speakerresults["Spk_ID"];
			//setcookie ("Spk_ID", $speakerid);
			mkdir("Imi/Spk_Img/".$speakerid);
			$Spk_Logo = $speakerresults["Spk_Logo"];	
			$Spk_Image = $speakerresults["Spk_Image"];	
			foreach( $HTTP_POST_FILES as $aFile )
			{
				if ($aFile['type'] == "image/gif" || $aFile['type'] == "image/jpeg" || $aFile['type']=="image/pjpeg")
				{
					copy ($aFile['tmp_name'], "Imi/Spk_Img/".$speakerid."/".$aFile['name']) 
						or die ("Could not copy"); 
					echo "";
				
				//$picname=$aFile['name'];
				}
			}
			$sql = "UPDATE speaker SET Spk_Logo = '".$Spk_Logo."' AND Spk_Image = '".$Spk_Image."' WHERE Spk_ID=".$speakerid;
			$results = mysql_query($sql) or die (mysql_error());
I bet that it has something to do with this:

Code: Select all

$Spk_Logo = $speakerresults["Spk_Logo"];	
			$Spk_Image = $speakerresults["Spk_Image"];
But I'm not certain.

Thanks so much for your help.

Posted: Wed Oct 12, 2005 2:12 pm
by pickle
call print_r($speakerresults) and see what you get.

Is 'None' the default value on the database side, or is it applied in your code somewhere?

Posted: Wed Oct 12, 2005 2:38 pm
by $var
Hi Pickle,

this is what I am getting from print_r:

Code: Select all

Array ( [0] => 37 [Spk_ID] => 37 [1] => FiRST [Spk_FName] => FiRST [2] => LaST [Spk_LName] => LaST )
And i have posted 'none' as the default in the code. It uses that to determine whether to show the image or the none.jpg that i set.

Posted: Wed Oct 12, 2005 2:40 pm
by pickle
Looking at the output, I'm not seeing a 'Spk_Image' entry. That's probably your problem.

Posted: Wed Oct 12, 2005 2:43 pm
by $var
why do you think that i am not getting a value?
i have passed the 'none', which, for the sake of data, is a value

does it have to do with the irregular names of the upload fields?

Posted: Wed Oct 12, 2005 2:46 pm
by pickle
Sorry, I got sidetracked. Try dumping $HTTP_POST_FILES (which is deprecated - $_FILES is the standard now). Also, try echoing the target location from the copy() command before you call copy().

Posted: Wed Oct 12, 2005 3:24 pm
by $var
gah... i don't get it...
i'm just going to send it to the guy who programmed it originally...
thanks for your help... but i'm lame... i can't figure it out... so i give up (wah)

Posted: Wed Oct 12, 2005 4:30 pm
by John Cartwright
or you could try

Code: Select all

$sql = "SELECT
        Spk_ID,
        Spk_Image,
        Spk_FName, Spk_LName
        FROM speaker WHERE
        Spk_FName='".str_replace("'","'",$_POST["fname"])."' AND Spk_LName='".str_replace("'","'",$_POST["lname"])."'";