Page 1 of 1

[SOLVED] File Upload - A Variable Issue

Posted: Mon Sep 26, 2005 9:07 am
by $var
Good Day,

I'm trying to get a file upload working for a CMS.
However, it doesn't work upload. I'm getting some errors... perhaps someone can spot the error.

It appears to me that the $cityid variable is not being passed along.


This is the trimmed INSERT statement:

Code: Select all

if($_POST['bpress']=="add")
	{
		$sql = "INSERT INTO city (
		City_Image,
		City_Name,
		VALUES (
		'none',
		'".$_POST["name"]."')";

This is the additional upload script that works off of the information above:

Code: Select all

$sql = "SELECT 
		City_ID, 
		City_Name, 
		FROM city WHERE 
		City_Name='".str_replace("'","'",$_POST["name"])."'";
			$cityresults = mysql_fetch_array($result);
			$cityid = $cityresults["City_ID"];
			//setcookie ("City_ID", $cityid);
			mkdir($_SERVER['DOCUMENT_ROOT']."httpdocs/Imi/City_Img/".$cityid);
			$picname="noimage.jpg";
			$City_Image = "City_Image";	
			$counter=1;	
			foreach( $HTTP_POST_FILES as $aFile )
			{
				if ($aFile['type'] == "image/gif" || $aFile['type'] == "image/jpeg" || $aFile['type']=="image/pjpeg")
				{
					copy ($aFile['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/City_Img/".$cityid."/".$aFile['name']) 
						or die ("Could not copy"); 
					echo "";
				
				//	$picname=$aFile['name'];
				
				}
				$picname=$aFile['name'];
				$City_Image = "City_Image".$counter;
				$sql = "UPDATE city SET ".$City_Image." = '".$picname."' WHERE City_ID=".$cityid;
				$counter++;
			}
The follow errors occur:

Code: Select all

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM city WHERE City_Name='Montreal'' at line 4error on select
server root/httpdocs/Imi/City_Img. is the folder that I am targeting.
I notice the slashes are reversed to what is being output...
Linux/Windows thing?

Code: Select all

Warning: mkdir(/httpdocs/Imi/City_Img/): No such file or directory

Code: Select all

Warning: copy(/httpdocs/Imi/City_Img//montreal.jpg): failed to open stream: No such file or directory Could not copy
If you can offer a word of advice on this, I would be ever so greatful.

bump.

Posted: Tue Sep 27, 2005 8:01 am
by $var
please, please look at this once more, to see if you have the wisdom to save this script.

and as a bump, an excerpt from The Decemberist's 'The Mariners Revenge Song'
[haunting, sailor-esque musical interlude lead by mandolin, accordion and tuba]

And then that fateful night
We had you in our sight
After twenty months at sea

Your starboard flank abeam
I was getting my muskets clean
When came this rumbling from beneath

The ocean shook
The sky went black
And the captain quailed

And before us grew
The angry jaws
Of a giant whale

[instrumental noise]
oh ohhhhhhhhhh
[screaming]
ohhhhh
[screaming]

(sorry for reposting within 24 hours, I forgot that my 9AM is your 8AM)

Posted: Tue Sep 27, 2005 8:07 am
by feyd
I'll let the bump slide..

as for your error.. you have a comma after City_name in your query.

Posted: Tue Sep 27, 2005 8:18 am
by $var
heheh... i think that is the second comma that you have pointed out.
i guess that commas will be the first thing that i check in the future...

Again, your forgiveness... please.
I didn't mean to bump hastily... stupid geographical regions. ;)