Results 1 to 9 of 9

Thread: Isset not working in chrome

  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    43
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Isset not working in chrome

    Code:
    <input type="submit" value="Delete" name="b1">
    <input type="submit" name="b2" value="Save">
    <?php
    if (isset($_POST["b1"])){
      echo "delete";
    } else if (isset($_POST["b2"])){
      echo "saved";
    }
    ?>
    It is not working in chrome but working in firefox, any one can help?

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Use !empty instead because $_POST is always set, even if it's empty.
    Eddy Proca
    I love Dropbox. Get it through my girlfriend's referral link (I reached my limit) and both you and her get 500 MB extra! Thanks and you're welcome!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Use !empty instead because $_POST is always set, even if it's empty.
    The whole array ($_POST) is always set. But some particular index like $_POST['x'] is only set if it was submitted. So isset() should work. However, it is possible that if you have a form submitted with an optional field "x", that $_POST['x'] would be set but empty, because they entered no text. In that case it would be equivalent to '', so empty() would work. But it depends on context.
    Overall, though, there's no harm using empty(), unless you'd like to distinguish the variable not existing from it having a blank value (as in the case of a form submission, where you might want to check whether the form has been submitted, with any value even the empty string).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    To add to my post above, in response to the original question, let me clarify a couple things:
    1. It is completely irrelevant which browser you are using; PHP will do exactly the same thing. However, in this case the difference is likely due to how those browsers handle forms (empty fields), so that PHP is getting different input (which of course would make a difference).
    2. My guess is that one browser is treating an empty form field as a null string (set to an empty value) and the other is treating the same empty field as not having a value. The information in the posts above should help you deal with this. Try isset() and !empty() to see which is best. Another approach would be to pre-process the input-- if no value for 'x' was submitted, set it to '', and so forth.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,920
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by ankush View Post
    Code:
    <input type="submit" value="Delete" name="b1">
    <input type="submit" name="b2" value="Save">
    <?php
    if (isset($_POST["b1"])){
      echo "delete";
    } else if (isset($_POST["b2"])){
      echo "saved";
    }
    ?>
    It is not working in chrome but working in firefox, any one can help?
    That's not a valid form. If it's made to be one, works fine here, or the same as Firefox (WAMP server, PHP 5.3, Chrome 30.x, Firefox 24.0):

    Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="submit" value="Delete" name="b1">
    <input type="submit" name="b2" value="Save">
    </form>
    <?php
    if (isset($_POST["b1"])){
      echo "delete";
    } else if (isset($_POST["b2"])){
      echo "saved";
    }
    ?>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Interesting. It certainly could be that the behavior of forms varies by whether they're valid HTML, or even by DOCTYPE.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jan 2012
    Location
    India
    Posts
    43
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    form.php

    Code:
    <form name="frm" action="submit.php" method="post">
    <input type="submit" value="Delete" name="b1">
    <input type="submit" name="b2" value="Save">
    </form>
    submit.php

    Code:
    <?php
    	if (!empty($_POST["b1"])){
    	echo "delete";
    	} else if (!empty($_POST["b2"])) {
    	echo "saved";
    	}
    ?>
    no luck, nothing works for me, neither isset nor !empty

    i have tried with

    Code:
    <?php
        if (!empty($_POST["b1"])){
      echo "delete";
    } else if (!empty($_POST["b2"])) {
      echo "saved";
    }
    	?>
    above condition working fine in firefox but print nothing when click on delete button and print saved when click on save in chrome

    and

    Code:
     <?php
        if (!empty($_POST["b1"])){
      echo "delete";
    } else {
      echo "saved";
    }
    	?>
    above condition working fine in firefox but in both cased chrome is printing saved

    i am trying to delete multiple records through delete button and wants to update a query through save button using check box in a single form, that's why i am trying to know, which button is clicked based on condition, so that i can perform particular action but no luck

    i am using (Version 30.0.1599.101 m) chrome, any other way to do this?

  8. #8
    Join Date
    Jan 2012
    Location
    India
    Posts
    43
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    Oops! tried on local host using easyPHP, working perfectly in chrome now. I think something wrong with my host, is this anything i can fix my self or i have to ask my host?

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,920
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    If it works in one browser on the live host, then it's hard to see how it's a problem with the host. However, I do have access to a live server with PHP where I can test things. I cannot give out the address though. On it, it works fine in Chrome. So that tends to support the theory that it's something with the host you're using. Perhaps they automatically attach/add code to their pages, and that's somehow messing things up in Chrome. Or perhaps they have some sort of weird configuration that messes up Chrome. If the former, a link to the live page would help us to see that, if the latter, you would have to have access to the configuration or ask the host.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. php isset simplify
    By keyboard in forum PHP
    Replies: 2
    Last Post: 03-01-2012, 03:31 AM
  2. PHP Session isset, help please
    By gravy834 in forum PHP
    Replies: 3
    Last Post: 02-15-2011, 11:32 AM
  3. Replies: 1
    Last Post: 05-25-2010, 02:30 PM
  4. Need help with isset function
    By Total_me in forum PHP
    Replies: 9
    Last Post: 04-19-2010, 10:26 AM
  5. isset/unset
    By pcbrainbuster in forum PHP
    Replies: 20
    Last Post: 03-14-2007, 08:45 AM

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
  •