SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using isset() to get value of a button

    I'm trying to use the isset() function to see if a variable is set, and if so, to perform a function, like so:
    Code:
    <?php 
    //if user cancels 
    
    if (isset($cancelphoto)){ 
    //delete file... 
    $ok = unlink($photo); 
     if ($ok === false){ 
     die("<br>Failed to delete "); 
     } 
    } 
    ?>
    and I have two buttons set up like this:
    Code:
    <?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?
    www.skullfarm.com

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you posting your form with a get or post request. I'm guessing it's a post.

    If so assume use $_POST['fieldname'] etc...

    This is quite an important thing to grasp within PHP - it's mentioned in the sticky in here

  3. #3
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are correct Unfortunately, it didn't help me; still the same results.
    www.skullfarm.com

  4. #4
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hi

    try this..it should work!!!
    if (isset("cancelphoto")){

  5. #5
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorry

    this is right...
    if(isset($_POST["cancelphoto"])) function_that_u_need();
    cya

  6. #6
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Silly question perhaps, but did you set the 'action' and 'method' for the form?

    And one debuging trick... at the beginning of the processing code just put his:
    PHP Code:
    echo '<br />Posted vars:</br><pre>'print_r($_POST]; echo '</pre>'
    And you'll see a dump of the posted variables. If not even the text 'Posted vars' doesn't show up it means that part of the script is not being processed.

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  7. #7
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not
    PHP Code:
    ($_POST
    but
    PHP Code:
    ($_POST

  8. #8
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arrrrrrggh typo\s typoss !
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac


Bookmarks

Posting Permissions

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