Hi there everyone,
I'm creating a classifieds system and I've gotten to the image upload system. I'm going to allow each ad to have a maximum of 6 images uploaded. I need to store the image names in the corresponding ad table. The only way I know how to place the image name in the proper place is to do a quite ridiculous nested if/else:
if(!ISSET($adcreate_image1) OR ($adcreate_image1=='')){
mysql_query("UPDATE classifieds_ads_temp SET image1 = '$adcreate_image1' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
if(!ISSET($adcreate_image2) OR ($adcreate_image2=='')){
mysql_query("UPDATE classifieds_ads_temp SET image2 = '$adcreate_image2' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
if(!ISSET($adcreate_image3) OR ($adcreate_image3=='')){
mysql_query("UPDATE classifieds_ads_temp SET image3 = '$adcreate_image3' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
if(!ISSET($adcreate_image4) OR ($adcreate_image4=='')){
mysql_query("UPDATE classifieds_ads_temp SET image4 = '$adcreate_image4' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
if(!ISSET($adcreate_image5) OR ($adcreate_image5=='')){
mysql_query("UPDATE classifieds_ads_temp SET image5 = '$adcreate_image5' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
if(!ISSET($adcreate_image6) OR ($adcreate_image6=='')){
mysql_query("UPDATE classifieds_ads_temp SET image6 = '$adcreate_image6' WHERE user_id = $user_id") or die("Failed to update ads_temp database.<br><br>" . mysql_error());
}else{
}
}
}
}
}
}
Which will work, but seems like an incredibly inefficient method of handling this.
Does anyone have any suggestions for making this a bit more elegant?
Thanks in advance for your time,
json