1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: PHP Conditional problem

Discussion in 'Web Design & Development' started by Firestone, Feb 16, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. Firestone

    Firestone Thread Starter

    Joined:
    Dec 24, 2006
    Messages:
    32
    I wrote this php code,

    PHP:
    <?php
    $User 
    $_POST["uname"];
    $Pass $_POST["pass"];
    if (
    $User "tyler" && $Pass "lambeth")
    {
    echo 
    "You are now logged in!";
    }
    else
    {
    echo 
    "Incorrect user name or password, please try again.";
    }
    ?>
    And it always displays "You are now logged in!" no matter what you enter. Anyone know whats wrong?
     
  2. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    A few simple errors:

    you need to add 2 = signs in the if() statment, like this:
    PHP:
    if ($User == "tyler" && $Pass == "lambeth"
    Try that, and see if it works.
     
  3. Firestone

    Firestone Thread Starter

    Joined:
    Dec 24, 2006
    Messages:
    32
    That was the problem thanks. It always seems like its the easiest thing, and I completely over look it...
     
  4. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    Don't worry, I always do that :p

    Just remember, you need to use 2 ='s in a conditional statement (==), just one won't work.

    Glad it worked mate.
     
  5. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    == means "equal to"
    = means "represents"

    Just keep that in mind for the future :)

    There's also === which means "identical to"
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/544722

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice