SkyRanger Posted January 24, 2013 Share Posted January 24, 2013 (edited) I am having a problem. $pic = image.jpg pic2 = pic3 = pic2 and pic3 there is nothing in database $query = "SELECT * FROM `cinvent` WHERE `oname`='$loggedin' and iid='$iid'"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); while($row = $result->fetch_assoc()){ if ($row['pic'] == 0 ) { echo "No Image"; } else { $file1 = $row['pic']; $delfile = "members/".$loggedin."/inventory/".$file1; unlink($delfile); } if ($row['pic2'] == 0 ) { echo "No Image 2"; } else { $file2 = $row['pic2']; $delfile2 = "members/".$loggedin."/inventory/".$file2; unlink($delfile2); } if ($row['pic3'] == 0 ) { echo "No Image 3"; } else { $file3 = $row['pic3']; $delfile3 = "members/".$loggedin."/inventory/".$file3; unlink($delfile3); } Even though there is nothing in the database it is still trying to run the unlink for pic2 and pic3 Not sure what the problem is. It will remove the image from 'pic' Edited January 24, 2013 by SkyRanger Quote Link to comment https://forums.phpfreaks.com/topic/273570-if-there-or-not/ Share on other sites More sharing options...
DavidAM Posted January 24, 2013 Share Posted January 24, 2013 You are checking to see if the database column is an integer value of zero if ($row['pic2'] == 0 ) { then you are using the value of the database column as a file name string $file2 = $row['pic2']; You should probably just test to see if the column is empty: if (empty($row['pic2'](( { Quote Link to comment https://forums.phpfreaks.com/topic/273570-if-there-or-not/#findComment-1407852 Share on other sites More sharing options...
PFMaBiSmAd Posted January 24, 2013 Share Posted January 24, 2013 What exactly is in the database? What does the following show when added inside of the while(){} loop - echo '<pre>'; var_dump($row); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/273570-if-there-or-not/#findComment-1407853 Share on other sites More sharing options...
SkyRanger Posted January 24, 2013 Author Share Posted January 24, 2013 Perfect, thanks DavidAM. New Code that works: $query = "SELECT * FROM `cinvent` WHERE `oname`='$loggedin' and iid='$iid'"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); while($row = $result->fetch_assoc()){ if (empty($row['pic'])) { echo "No Image"; } else { $file1 = $row['pic']; $delfile = "members/".$loggedin."/inventory/".$file1; unlink($delfile); } if (empty($row['pic2'])) { echo "No Image 2"; } else { $file2 = $row['pic2']; $delfile2 = "members/".$loggedin."/inventory/".$file2; unlink($delfile2); } if (empty($row['pic3'])) { echo "No Image 3"; } else { $file3 = $row['pic3']; $delfile3 = "members/".$loggedin."/inventory/".$file3; unlink($delfile3); } } Quote Link to comment https://forums.phpfreaks.com/topic/273570-if-there-or-not/#findComment-1407854 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.