Basic image select than insert question

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
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Basic image select than insert question

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

yeah, I know...

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