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 4 of 4

Thread: !isset

  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts

    !isset

    I am trying to find a way to tell if
    Code:
    $submit=$_POST['submit'];
    is set or not, i am using
    Code:
    if(!isset($submit)) { echo "submit is set";}
    but it displays everytime whether the submit button is clicked or not. any ideas on how to do what I want to do?

    tia.

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    if(!isset($submit)) { // if $submit is NOT set
    echo "submit is NOT set";

    I think you have mixed up your code

    PHP Code:
    $submit=$_POST['submit']; 

    if(isset(
    $submit)) { // if $submit is set
    echo "submit is set";

    Also note that PHP is case sensitive so Submit is different to submit.
    This can cause problems with forms if you use a submit button named submit

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am actually trying to check to see if $submit has already been entered,
    I have the
    Code:
    $submit=$_POST['submit'];
    after the initial
    Code:
    if(!isset($submit)) { // if $submit is NOT set 
    echo "submit is NOT set"; 
    }
    otherwise on my next page of search results, they don't come up until after you hit the submit button again.

    thanks for the heads up, but I do everything in lower case so as not to get things confused.

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you load a page then submit will not be set and you will see the message.
    If you have submitted the page then submit will be set.

    I haven't seen your code but I still think you have it the wrong way around.


    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    $submit
    =$_POST['submit'];

    if(isset(
    $submit)){ echo "submit is set"; }
    ?>
    <form name="form1" method="post" action="">
      <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>


  •  

    Posting Permissions

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