LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-30-2006, 11:27 PM   #1
veritas
Member
 
Registered: Aug 2003
Location: Dallas,TX
Distribution: Ubuntu Server, Slackware, Red Hat 6.1
Posts: 241

Rep: Reputation: 30
problem with php logic


Hi,

If I leave out the ?name= from logic.php it correctly displays "no name specified." But if I do logic.php?name=Jack it displays wrong name. Same with a bogus value. I tried changing the operator to !=, but the code outputs "name accepted" for any value using this method. I would appreciate any tips with this.
Code:
<?php
        $var = $_GET["name"];

        if (!$var)
        {
                echo "no name specified";
        }
        else
        {
                if ($var !== ("Jack" || "Jill" || "Ted" || "Sarah"))
                {
                        echo "wrong name";
                }
                else
                {
                        echo "name accepted";
                }
        }
?>
 
Old 12-30-2006, 11:51 PM   #2
pnellesen
Member
 
Registered: Oct 2004
Location: Missouri, USA
Distribution: Slackware 12.2, Xubuntu 9.10
Posts: 371

Rep: Reputation: 31
I think your evaluation needs to be as follows:
Code:
if ($var != "Jack" && $var != "Jill" && $var != "Ted" && $var != "Sarah")
If any of those names is entered, you should see "name accepted"
 
Old 12-31-2006, 12:01 AM   #3
veritas
Member
 
Registered: Aug 2003
Location: Dallas,TX
Distribution: Ubuntu Server, Slackware, Red Hat 6.1
Posts: 241

Original Poster
Rep: Reputation: 30
Thanks! That did the trick
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php validation logic spoody_goon Programming 5 01-14-2006 07:31 PM
Logic Problem lucky6969b Programming 9 12-18-2005 10:44 PM
A real teaser of a problem, it defies logic... (xfree86 and bootup) adamis Mandriva 2 02-15-2004 03:20 PM
RH7.2 problem with Xconfigure using cirrus logic GDA5436 Stonesbeer Red Hat 6 09-24-2003 02:39 AM
Avance Logic sound card problem ShadowLux Linux - Hardware 1 08-19-2002 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration