Jump to content

if there or not


SkyRanger

Recommended Posts

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 by SkyRanger
Link to comment
Share on other sites

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'](( {

Link to comment
Share on other sites

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);
       }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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