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.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
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");
                }
    
?>
Reply With Quote

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

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 154
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...)
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
  #4 (permalink)  
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 }?
Reply With Quote
  #5 (permalink)  
Old Aug 2nd, 2007, 14:28
karinne's Avatar
SuperMember

SuperMember
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?!
Reply With Quote
  #6 (permalink)  
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
Reply With Quote
  #7 (permalink)  
Old Aug 2nd, 2007, 14:43
karinne's Avatar
SuperMember

SuperMember
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?
};
}
Reply With Quote
  #8 (permalink)  
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.
Reply With Quote
  #9 (permalink)  
Old Aug 2nd, 2007, 14:55
karinne's Avatar
SuperMember

SuperMember
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
Reply With Quote
  #10 (permalink)  
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?
Reply With Quote
  #11 (permalink)  
Old Aug 2nd, 2007, 15:01
karinne's Avatar
SuperMember

SuperMember
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?
Reply With Quote
  #12 (permalink)  
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...'
Reply With Quote
  #13 (permalink)  
Old Aug 2nd, 2007, 15:16
karinne's Avatar
SuperMember

SuperMember
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) { 

Reply With Quote
  #14 (permalink)  
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.
Reply With Quote
  #15 (permalink)  
Old Aug 2nd, 2007, 16:35
karinne's Avatar
SuperMember

SuperMember
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");
    
    }
    
}
    
?>
Reply With Quote
  #16 (permalink)  
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.
Reply With Quote
  #17 (permalink)  
Old Aug 2nd, 2007, 17:19
karinne's Avatar
SuperMember

SuperMember
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
Reply With Quote
Reply

Tags
form, none

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeat data entered in a text box... and maybe change it? simbo1231 JavaScript Forum 4 Dec 2nd, 2007 10:24
Setting Form Values to Previously Entered Values masonbarge PHP Forum 6 Oct 17th, 2006 17:36
Open different pages depending on value entered into input box IanW PHP Forum 5 Sep 15th, 2006 17:48
Open a specific page dependent on what is entered into a criteria box??? IanW Web Page Design 2 Sep 15th, 2006 12:39


All times are GMT. The time now is 07:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43