I'm trying to use the isset() function to see if a variable is set, and if so, to perform a function, like so:

<?php
//if user cancels 

if (isset($cancelphoto)){
//delete  file...
$ok = unlink($photo);
		if ($ok === false){
	die("<br>Failed to delete ");
	echo $photo; 
	}
}
?>

and I have two buttons set up like this:

<?php
if (is_readable($photo)){
echo "<input type=\"submit\" value=\"Add image\" onClick='opener.showProgress(); document.uploadurl_form.submit()'>";
echo "<input type=\"button\" name=\"cancelphoto\" value=\"Cancel\">";
}
?>

...but nothing happens... no error message, and the file does not get deleted. What am I doing wrong?

    Change your "<input type=\"button\"
    to "<input type=\"submit\"

    Then you need to be testing for it in the returned $_POST array.

      when I change it to "submit", it performs the "add image" function from the other button... can you have two submit type buttons?

        You should be using 2 different names:

        "<input type=\"submit\" name=\"addimage\" value=\"Add image\" onClick='opener.showProgress(); document.uploadurl_form.submit()'>";

        echo "<input type=\"submit\" name=\"cancelphoto\" value=\"Cancel\">";

          hmm, still no go. I gave the first button a name as suggested, but clicking the cancel button (as a submit button) still performs the addimage button's function...

            Will need to see your complete form action to see what page is being called, variables being passed, and methods used. Then, need to see the scripting on the resulting page to see how you are checking for the variables.

              if (is_readable($croppedPhoto)){
              echo "<br><br><br><center>Image has been cropped and saved to a temporary directory. <br>Click on the button below to add the new image to your album.</center>";
              }
              ?>

              <?php
              //if user cancels cropped photo...

              if (isset($cancelcrop){
              //delete original cropped temp file...
              $ok = unlink($croppedPhoto);
              if ($ok === false){
              die("<br>Failed to delete ");
              echo $croppedPhoto;
              }
              }
              ?>

              <br>

              <?php echo makeFormIntro("save_photos.php",
              array("name" => "uploadurl_form",
              "method" => "POST")); ?>

              <input type="hidden" name="urls[]" size=40 value=<?php echo $croppedPhoto ?>>
              <br>
              <input type="hidden" name="setCaption" checked value="1">
              <input type = "hidden" name="croppedPhoto" value=<?php echo $croppedPhoto ?>>
              <br>
              <center>
              <?php
              if (is_readable($croppedPhoto)){
              echo "<input type=\"submit\" name=\"addimage\" value=\"Add image to album\" onClick='opener.showProgress(); document.uploadurl_form.submit()'>";
              echo "<input type=\"button\" name=\"cancelcrop\" value=\"Cancel\">";
              }
              ?>
              </center>
              </form>

                I guess that this actually is part of your save_photos.php.

                If so, then you need to be checking that the variable was actually passed in the post variable array:
                $_POST['cancelcrop']

                  Write a Reply...