Page 1 of 1

Basic image select than insert question

Posted: Fri Jun 09, 2006 2:20 pm
by imstupid
Ok, I can insert an image file from an html form into a temporary holding table fine.

Then, I want to select the contents of the image field from the temporary table, and write it into a permanent table, however an a little unsure about the process.


Selecting the file from the temporary table:

Code: Select all

$image = mysql_query("SELECT image FROM holdingtable WHERE name='$imageone'") 
         or die(mysql_error()); 

$imagearray = mysql_fetch_array( $image )
        or die(mysql_error()); 

    $oldimage = $imagearray['image'] ;

// Then inserting:

mysql_query("INSERT INTO permtable (image) VALUES ('$oldimage ')");
However the image doesn't seem to appear and I want to make sure it writes correctly. It writes something, but I think it's just a bunch of jargon.

Long story short, my question is, do I need to use mysql_fetch_array, or is there another process? When I don't use it, and just run the query:

Code: Select all

mysql_query("INSERT INTO permtable (image) VALUES ('$image')");
It inserts Resource ID #13


Or in other words, how can I copy the image contents (a.k.a. The actual file) from one table to another?

Thanks everybody.

Posted: Fri Jun 09, 2006 2:27 pm
by feyd
I'd use an INSERT .. SELECT so you don't have to dump the data to php and back into the database again, however I still think storing image data in a database is silly.

Posted: Fri Jun 09, 2006 3:48 pm
by imstupid
yeah, I know...

that insert...select query is pretty nice and time-saving. thanks again.