allow user to add image to a product they post

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

allow user to add image to a product they post

Post by ninethousandfeet »

hello,

i'm not exactly sure if my problem is with php or my database, but i'm pretty sure it all starts with the database for this one. right now i have allow users to post a new product they can sell, similar to someone making a post on craigslist for example. however, i do not currently allow users to add an image of their product, which brings me here... i have read that it is a better practice to store the images in a separate hash file system, but before i get to figuring that out, i need more of a starting point.

right now i have a postTable which stores the post_id(pk, auto_increment), post_title, product_name, and user_id.
i have just created an imageTable which stores the image_id(pk, auto_increment), imagedata(mediumblob), imagetype, and post_id.

my question: with the insert form on the 'Post New Product' page, how can i have just one form to submit the information into the postTable and also insert the information into the imageTable(only if an image is added)?

my current results leave me with an error message telling me to check my sql syntax on line 1, null, null... i just have it setup like this: $insertsql = insert into postTable (columns...) VALUES (%s....) $result THEN I HAVE $insertsql = insert into imageTable (columns...) VALUES (%s....) $result .

thank you for anyone taking a look and for the help.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: allow user to add image to a product they post

Post by LanceEh »

I haven't dealt to much with images and databases, but the way I would approach it is if there is a POST variable related to the image, you could do an IF statement.

So:

Code: Select all

if (isset($_REQUEST['pic'])){
then update database with pic info here
}
This is pretty much a shot in the dark for me, but may lead you in the right direction (hopefully).

Take care.
Post Reply