IF value entered is nothing?

This is a discussion on "IF value entered is nothing?" within the PHP Forum section. This forum, and the thread "IF value entered is nothing? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 1st, 2007, 19:07
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
IF value entered is nothing?

I forgot how to do this and I can't find anything in google.

I need a quick if to search if $gamertag has anything entered, if it doesn't i need it display an error message otherwise display the below.

Thanks.


PHP: Select all

<?php
    $answer 
$_POST['style'];
    if(
$answer == "Homecourt #1"){
        echo 
"There is no Homecourt #1";}
    elseif(
$answer == "Homecourt #2"){
        echo 
"There is no Homecourt #2";}
    elseif(
$answer == "Homecourt #3"){
        echo 
"There is no Homecourt #3";}
    elseif(
$answer == "Gears Of War #1"){
        echo 
"There is no Gears Of War #1";}
    elseif(
$answer == "GTA IV #1"){
        echo 
"There is no GTA IV #1";}
            else {
                echo (
"Error, please go back and try again");
                }
    
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 1st, 2007, 22:27
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 161
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

if (isset($gamertag))

or

if ($gamertag)

or

if (trim($gamertag))

or if(trim($gamertag) != "")

should all return true if $gamertag is set. (I think...)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 2nd, 2007, 00:17
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 2nd, 2007, 14:24
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

PHP: Select all

    <?php
    
if (isset($gamertag)) {
    echo 
    
$answer $_POST['style'];
    if(
$answer == "Homecourt #1"){
        echo     include(
"code/homecourt1.php");
                echo (
"<br><br><br>");
                include(
"code/getform.php");}
        
        elseif(
$answer == "Gears Of War #1"){
        echo     include(
"code/gearsofwar1.php");
                echo (
"<br><br><br>");
                include(
"code/getform.php");}
            
        elseif(
$answer == "GTA IV #1"){
            echo 
"There is no GTA IV #1";}
            
            else {
                echo (
"Error, please go back and try again");
                };}
    
    else { echo
"Please Enter your Gamertag";}
    
?>
If i don't enter anything it still displays the above code, can you see what's wrong? I'm thinking maybe I'm missing an }?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 2nd, 2007, 14:28
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

What's with the echo's all over the place?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 2nd, 2007, 14:36
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Yeah actually, I won't need them now

Can you spot my problem though? I'll clean the echos up before i update the site with the working if
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 2nd, 2007, 14:43
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

There's an else { } too many ... at the bottom?! and a few things wrong.

Here's what I got when removing the echo's

PHP: Select all

<?php
if (isset($gamertag)) {
    
$answer $_POST['style'];
    if(
$answer == "Homecourt #1"){
        include(
"code/homecourt1.php");
        echo (
"<br><br><br>");
        include(
"code/getform.php");
    
    } elseif (
$answer == "Gears Of War #1") {
        include(
"code/gearsofwar1.php");
        echo (
"<br><br><br>");
        include(
"code/getform.php");
        
    } elseif (
$answer == "GTA IV #1") {
        echo 
"There is no GTA IV #1";
        
    }

else {
    echo (
"Error, please go back and try again");
};
}
    
else { 
    
    echo 
"Please Enter your Gamertag";
}
    
?>
You're echo ("<br><br><br>"); shouldn't have the () wrapping the text

What's this?
};
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 2nd, 2007, 14:47
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

That's ending;

PHP: Select all

else {
    echo (
"Error, please go back and try again");
}; 
And then ending the

PHP: Select all

if (isset($gamertag)) { 

I think.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 2nd, 2007, 14:55
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Ah ... like this then
PHP: Select all

<?php
if (isset($gamertag)) {
    
$answer $_POST['style'];
    if(
$answer == "Homecourt #1"){
        include(
"code/homecourt1.php");
        echo 
"<br><br><br>";
        include(
"code/getform.php");
    
    } elseif (
$answer == "Gears Of War #1") {
        include(
"code/gearsofwar1.php");
        echo 
"<br><br><br>";
        include(
"code/getform.php");
        
    } elseif (
$answer == "GTA IV #1") {
        echo 
"There is no GTA IV #1";
        
    } else {
        echo (
"Error, please go back and try again");
    
    }
    
} else { 
    
    echo 
"Please Enter your Gamertag";
}
    
?>
Right ... that's makes sense
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 2nd, 2007, 14:59
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Looks much cleaner(Thanks) and I doubt you know but you also fixed another problem i had, it would randomly display a '1' after the image

Any idea as to why the isset is not working?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 2nd, 2007, 15:01
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Has $gamertag been given a value before this script? How do they get to this point?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Aug 2nd, 2007, 15:13
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

http://www.360sigs.com/gamercards.php

They get it from entering there tag, enter my tag 'PicoDeath and at the top it will display 'Thank you PicoDeath', enter no tag and it KNOWS nothing is in the form because it displays 'Thank you No username here for using...'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Aug 2nd, 2007, 15:16
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Have you tried

PHP: Select all

if (!$gamertag) { 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Aug 2nd, 2007, 15:20
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Put that in just now, it displays 'Enter a gamertag' yet you entered one and it displays it at the top. And if you don't enter one it displays the code i want it too.

I guess i just switch the contents of the IF around for it to work?

Fixed thanks.

Last edited by PicoDeath; Aug 2nd, 2007 at 16:34.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Aug 2nd, 2007, 16:35
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Opps ... right...hehe ... yes

I guess it would something like this

PHP: Select all

<?php
if (isset($gamertag)) {
    
    echo 
"Please Enter your Gamertag";
    
} else { 
    
$answer $_POST['style'];
    if(
$answer == "Homecourt #1"){
        include(
"code/homecourt1.php");
        echo 
"<br><br><br>";
        include(
"code/getform.php");
    
    } elseif (
$answer == "Gears Of War #1") {
        include(
"code/gearsofwar1.php");
        echo 
"<br><br><br>";
        include(
"code/getform.php");
        
    } elseif (
$answer == "GTA IV #1") {
        echo 
"There is no GTA IV #1";
        
    } else {
        echo (
"Error, please go back and try again");
    
    }
    
}
    
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Aug 2nd, 2007, 17:13
Reputable Member
Join Date: Sep 2006
Location: England
Age: 20
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Haha, I asked because you were replying so fast in the end i just tried it and it worked.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Aug 2nd, 2007, 17:19
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: IF value entered is nothing?

Phew! 'cause if you would've told it didn't work ... I was gonna pack up my $hit and leave!

Glad to we got that working
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!