SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Thread: $_GET help

  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET help

    Hi Guys

    I am trying the code below and it just does not do anything

    if($_GET['feet'] == 0){blah blah}

    I also tried

    if($_GET['feet'] < 1){blah

    Basically I want to trap zero ,but it does not do anything when I enter
    zero into the text field.

    Please help
    NIva

  2. #2
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should you not be using $_POST if you are submitting from a form? I have always under the impression that $_GET is for URL parameters.

  3. #3
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you enter zero into the text field it sees it as a string, not as boolean true/false.

    Use $_POST as matt said, and try:

    if ($_POST['feet'] == '0') { code here }

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mattih5
    Should you not be using $_POST if you are submitting from a form? I have always under the impression that $_GET is for URL parameters.
    Yes it is normally. Unless you've specified your form to use method=get.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LemoNade
    When you enter zero into the text field it sees it as a string, not as boolean true/false.

    Use $_POST as matt said, and try:

    if ($_POST['feet'] == '0') { code here }
    HI GUys

    I tried $_POST and $_REQUEST, both donot work, I also
    tried settype as well to change the field to an integer, still no luck

    Please help
    NIva

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    OK, the following code works for me....
    PHP Code:
    <?php 
    if(isset($_GET['submit'])) {
        if(
    $_GET['entertext'] == '0') {
            echo 
    'its 0';
            } else {
            echo 
    'Its not 0, its '$_GET['entertext'];
            }
        }
    ?>

    <form name="getTest" action="" method="get">
        <input type="text" name="entertext">
        <input type="submit" name="submit">
    </form>
    See if there are any differences to yours.

    Cheers

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI Spikz

    I cannot understand, it still does not work for me,here my code
    PHP Code:
    <?php    if(isset($_GET['Submit'])){
        if(!empty(
    $_GET['feet'])){
        if(!
    ereg("^([0-9]{1})$"$_GET['feet'])){
        
    $_SESSION['feet']=$_GET['feet'];
        
    $error_message[]= "Invalid entry for height.";}
         if(
    $_GET['feet'] == '0'){
        
    $_SESSION['feet']=$_GET['feet'];
        
    $error_message[]= "Invalid entry for height.";}
        else{
        
    $_SESSION['feet']=$_GET['feet'];}}}    
    ?>

    Funnything -I tried it on the webhost and my local pc server setup as well,no luck

  8. #8
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI Guys

    Something that I noticed for the first time

    In my code I still have

    if($_GET['feet'] == '0'){ ....

    but if I enter 0(single zero) in the text box, nothing happens,if I enter
    double zero (00) I get an invalid message and if I enter space zero ( 0)
    I get an error.

    Any idea whats happening here,I tried trim() as well.


    NIva

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    OK try this,
    PHP Code:
    session_start();
      if(isset(
    $_GET['Submit'])){ 
        if((!empty(
    $_GET['feet']) && $_GET['feet'] != '0')) { 
                
    $_SESSION['feet']=$_GET['feet'];
                } else {
                
    $_SESSION['feet']=$_GET['feet']; 
                
    $error_message[]= "Invalid entry for height.";
            }
        } 
    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey SpikZ

    What could it be, it still does not work, I cannot understand, I have been
    battling with this all day .THis is very strange.

    If I do a gettype() on that field, it shows string

    Any thoughts please man
    Niva

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    what is your output if any from the code I gave you above and what is the output from your own code?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem is that nothing heppens when you enter zero in the text field,everything works 100% but when u enter 00 its throws an error.

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    give me some more code around the part you posted.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Spikz,there is actually no more code,I am working on a very small script to
    calculate BMI , so I am trapping anyone that enter zero as there feet,

    Nothing complicated at all...

    NIva

  15. #15
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Post your form code.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    UPDATE:
    The problem was resolved by using double quotes around 0 instead of single...



    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks SpikeZ
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •