Upload not setting Image Name... ah!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Upload not setting Image Name... ah!

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Looking at the output, I'm not seeing a 'Spk_Image' entry. That's probably your problem.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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"])."'";
Post Reply