1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple If statement to stop blank form entry

Discussion in 'PHP' started by Dirty-Rockstar, Aug 12, 2007.

  1. #1
    What can i add above or below this to replace a blank form entry to the word "anonymous" without making the code explode. or do you need more code :p
    I know i can do it with an if statement but i just cant figure out how
    thanks


    
    </p>
    <form method="post" action="hminsbest.php">
    <input type="hidden" name="wordid" value="<?=$_SESSION['gcid']; ?>" />
    <input type="hidden" name="besttime" value="<?=$tempo; ?>" />
    <input type="hidden" name="besttent" value="<?=$tentativi; ?>" />
    <p><?=INSRT; ?><input type="text" name="newbest" size="20" maxlength="20" />
    <input type="submit" value="<?=SBMT; ?>" name="go" /></p>
    </form>
    HTML:

     
    Dirty-Rockstar, Aug 12, 2007 IP
  2. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if(strlen($var) === 0) { $var = "anon"; }

    something like that
    or
    if($var == '') { $var = "anon"; }

    either way should be fine.
     
    powerspike, Aug 12, 2007 IP
  3. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #3
    You could also use
     
    if(empty($var)) 
     { 
    $var = "anonymous"; 
     }
    
    
    PHP:
     
    killerj, Aug 12, 2007 IP
    Dirty-Rockstar likes this.
  4. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi Dirty-Rockstart, have the above suggestions solved the issue for you ?
     
    powerspike, Aug 14, 2007 IP