Jump to content

[SOLVED] Upload Array please help!


iceblox

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/62237-solved-upload-array-please-help/
Share on other sites

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.