iceblox Posted July 28, 2007 Share Posted July 28, 2007 Hi guys, I have an upload image script which works on array, allowing you to set a max number of images. That part is all fine but im having trouble with getting it into a mysql database. I have worked it out if you just want each file as a new row. But what I want to do is save each image to a specfic column in the table. For Example I have allowed a max of 6 images and have 6 colums in the table named img1 img2 etc and i want img 1-6 from the array into each of those. Whilst keeping them on the same row. This is my Uploading code while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ $filename = $value; $add = "images/$filename"; copy($_FILES[images][tmp_name][$key], $add); } } $result = $db->sql_query("INSERT INTO cars (MakeName, CarName, MakeID, CarType, Text, Img1, Img2, Img3, Img4, Img5, Img6, ActiveImg, caractive) VALUES ('".forSql($_POST["MakeName"])."', '".forSql($_POST["CarName"])."', '".forSql($_POST["MakeID"])."', '".forSql($_POST["CarType"])."', '".forSql($_POST["text"])."', '$filename', '$filename', '$filename', '$filename', '$filename', '$filename', '$ActiveImg', '".forSql($_POST["active"])."')"); I have tried [$Key] after file name and without the [] but im not very good with arrays so im not sure of the output. Any help would be appreciated. Thanks Phil Quote Link to comment Share on other sites More sharing options...
iceblox Posted July 28, 2007 Author Share Posted July 28, 2007 Anyone got any ideas? Quote Link to comment Share on other sites More sharing options...
iceblox Posted July 29, 2007 Author Share Posted July 29, 2007 Anyone? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 Don't double post. I'm removing the other one. Quote Link to comment Share on other sites More sharing options...
zq29 Posted July 29, 2007 Share Posted July 29, 2007 Just a heads up, that's not exactly good practice in terms of database design. I'd suggest you create two more tables, image and image_car, image would contain the fields id,path and image_car would have id,image_id,car_id. You'd then "link" your images to your cars using the image_car table. This way you could attach as many or as little images as you wish... Quote Link to comment Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 http://us.php.net/features.file-upload That should help you. I simply Googled 'php uploads' Look at the script where it has the userfile[] inputs. Quote Link to comment Share on other sites More sharing options...
iceblox Posted July 29, 2007 Author Share Posted July 29, 2007 Thanks guys ill look into these suggestions. Apologies for the double post. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.