Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    isset not working correctly

    the isset in my code doesnt seem to do what its suppose to, have i gone wrong somewhere,

    PHP Code:
    echo "1 ".$_FILES['cons_image'.$id[3]]['name']."<br />";
    if (isset(
    $_FILES['cons_image'.$id[3]]['name'])){
        
    $q "SELECT image FROM bands WHERE id = '$id[3]'";
        echo 
    "2 ".$q."<br />";
        
    $r mysql_query($q) or die($q."<br/><br/>".mysql_error());
        while(
    $row mysql_fetch_array($r)){
            echo 
    "4 ".$row['image']."<br />";
            
    $file "../".$row['image'];
            echo 
    "5 ".$file."<br />";
        }
        if (isset(
    $row['image'])){
            echo 
    "6 Unlink Area";
            exit;
            
    unlink($file); 
            
    $file explode("$table/thumb",$file);
            
    $file $file[0]."$table".$file[1];
            
    unlink($file);
        }
    }
    exit; 
    echo output.

    1 testing-testing-123.jpg
    2 SELECT image FROM bands WHERE id = '44'
    4 images/bands/thumb/test102.jpg
    5 ../images/bands/thumb/test102.jpg

    As you can see $row['image'] has content so it is "set" so it should run the unlink code yet it skips it all together.

    with the
    Code:
    if (isset($_FILES['cons_image'.$id[3]]['name'])){
    if no file is being uploaded then it should just skip all this code yet it is being run.

    am i going about this the wrong way or have i missed something out.

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    isset has been having issues from what i know for some time now. not sure what the issues are but try this and see what happens

    my understanding is that if you use if strait up, if it has contents (set) it will be true if it is empty it will be false.

    PHP Code:

    if($_FILES['cons_image'.$id[3]]['name']){ 
    let us know if that works please.

  • #3
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I tried just using plain if but it didnt work

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    ok well thanks for that info, thats why i wanted to ask because i have been just removing the isset all together and going strait and it seems to work for me every time, but i wanted to ask to make sure it worked for you also.

    are you getting this from a form input by chance.

    if so can you post your form please

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by durangod View Post
    isset has been having issues from what i know for some time now.
    No, you're wrong. There is nothing wrong with isset and it has no issues. It's the way its used and the way that its understood that has issues.

    @Kersh: I suspect your isset is working properly but you may be confused with where you're expecting to see a file name. You show the output for number 1 and 2 and then say that when no file is uploaded the code still runs. If no file is uploaded then number 1 should fail at the first hurdle because there will be no file name to print yet you're not mentioning any error messages (Do you have error reporting on?).

    With regards to the unset of your file I suspect you have a file path fault. It's easy in php to be convinced you've got it right, spend hours on it pulling your hair out and then find its very slightly wrong. Trust me I've done it plenty of times. You should be using:

    PHP Code:
    if (file_exists($file))
       {
       print 
    "$file found";

       if (
    unlink($file))
          {
          print 
    "$file deleted";
          }
       }
    else
       {
       print 
    "$file not found or deleted";
       } 
    This will show you if you have the right file path.
    Last edited by tangoforce; 09-08-2011 at 03:11 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    then i misunderstod, my apologies tango.

  • #7
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok just been doing a bit more testing and
    Code:
    if ($_FILES['cons_image'.$id[3]]['name']){
    does work correctly as tested it without running round after anyone here. (sorry bout that)

    i put my $row['image'] in to a $image variable and then set the if to check that and it works now,

    seems $row['image'] was empty outside the while so thats why


    thanks for advice

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    PHP Code:
        if (isset($row['image'])){
            echo 
    "6 Unlink Area";
            exit;
            
    unlink($file); 
    Of course.. calling exit before unlink will also guarantee that unlink doesn't work
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    lmao i didnt even notice that omg wow tango has eyes like an eagle or im just old and blind lol.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    $row['image'] *must* be false outside of the while. The condition states that it will iterate UNTIL it can be evaluated to false. A recordset fetch of NULL produces this false condition meaning that $row is now populated as NULL and not array.
    So yeah, you're options are either to deal with $row['image'] within the scope where it will exist, or capture the results in a predeclared variable for use outside of the while.

    Edit:
    Actually, there is an exception to this rule. If you break from the loop, it will still be populated with the last known $row since a false condition was never required in order to terminate the loop.

  • #11
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    isset function is not working properly on internet explorer. did you test these things on internet explorer.

  • #12
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by mindblaster View Post
    isset function is not working properly on internet explorer. did you test these things on internet explorer.
    The browser shouldn´t care, The PHP is excecuted on the server, not on the client´s browser

  • #13
    New Coder
    Join Date
    May 2011
    Location
    UK
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    PHP Code:
        if (isset($row['image'])){
            echo 
    "6 Unlink Area";
            exit;
            
    unlink($file); 
    Of course.. calling exit before unlink will also guarantee that unlink doesn't work
    yeah i put that there so it didnt do the unlink, got fed up of reuploading the image to test. :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •