Hello,
Wondering if someone can help me with the creation of a query.
Basically I have a form like so:
//Process first Image if it is selected
if (!empty($_FILES['ufile_one']['name'])) {
//Pic Code uploading removed
$pic_exists1 = " image1='12', "; //Add to Query
//Process second Image if it is selected
if (!empty($_FILES['ufile_two']['name'])) {
//Pic Code uploading removed
$pic_exists2 = " image2='13', "; //Add to Query
}
//Process third Image if it is selected
if (!empty($_FILES['ufile_three']['name'])) {
//Pic Code uploading removed
$pic_exists3 = " image3='14' "; //Add to Query
}
$result = mysql_query("UPDATE tbl set $pic_exists1 $pic_exists2 $pic_exists3 WHERE id=".$_GET['id']);
?>
<input name="ufile_one" type="file" id="ufile_one" />
<input name="ufile_two" type="file" id="ufile_two" />
<input name="ufile_three" type="file" id="ufile_three" />
Now, one pic could be uploaded, or two pics or three pics and I want to include the Add to query bits in my query. So for example if the first two files were uploaded but the third now my query would look like:
UPDATE tbl set image1='12', image2='13', WHERE id=".$_GET['id']);
Now my problem here is the last comma. If the third file was uploaded the query would run fine, but as it’s not the query will not work due to the last comma just before WHERE.
Any suggestions of a way around this?
Thank You