Web Analytics Made Easy -
StatCounter isset not working correctly - CodingForum

Announcement

Collapse
No announcement yet.

isset not working correctly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.
    I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

    Comment


    • #3
      I tried just using plain if but it didnt work

      Comment


      • #4
        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
        I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
        A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
        durangod is short for durango dave

        Comment


        • #5
          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; Sep 8, 2011, 10:11 AM.
          "Tango says double quotes with a single ( ' ) quote in the middle"
          '$Name says single quotes with a double ( " ) quote in the middle'
          "Tango says double quotes ( \" ) must escape a double quote"
          '$Name single quotes ( \' ) must escape a single quote'

          Comment


          • #6
            then i misunderstod, my apologies tango.
            I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
            A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
            durangod is short for durango dave

            Comment


            • #7
              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

              Comment


              • #8
                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
                "Tango says double quotes with a single ( ' ) quote in the middle"
                '$Name says single quotes with a double ( " ) quote in the middle'
                "Tango says double quotes ( \" ) must escape a double quote"
                '$Name single quotes ( \' ) must escape a single quote'

                Comment


                • #9
                  lmao i didnt even notice that omg wow tango has eyes like an eagle or im just old and blind lol.
                  I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
                  A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
                  durangod is short for durango dave

                  Comment


                  • #10
                    $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.
                    PHP Code:
                    header('HTTP/1.1 420 Enhance Your Calm'); 
                    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                    Comment


                    • #11
                      isset function is not working properly on internet explorer. did you test these things on internet explorer.

                      Comment


                      • #12
                        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

                        Comment


                        • #13
                          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

                          Comment

                          Working...
                          X
                          😀
                          🥰
                          🤢
                          😎
                          😡
                          👍
                          👎