Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default [PHP] script not running.

    iyaar,

    I coded this PHP script recently and there's a error saying "Password was incorrect." even when it is correct.

    Link: http://edd-dev.awardspace.com/php/index.php

    Page code:
    PHP Code:
    <?php
    $pass1 
    == 'admin';//Login pass.

    if(!$_POST['submit']){
      echo(
    "
      <form action=\"index.php\" method=\"POST\">
      PASSWORD: <input type=\"text\" name=\"password\">
      <br />
      <input type=\"submit\" name=\"submit\" value=\"LOGIN\">
      </form>
      "
    );
    }else{
      
    $password == $_POST['password'];
      if(
    $password == $pass1){
        echo(
    "The password was correct.");
      }else{
        echo(
    "The password was incorrect.");
      }
    }
    ?>
    I dunno what's wrong so any help appreciated!
    Last edited by lolwut; 22-08-2007 at 11:08 AM.
    i've been here for over 8 years and i don't know why

  2. #2
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    == is a comparison.
    = is used to set variables etc.

  3. #3
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    Yeah as Tom said, you need to change $pass1 == 'admin';//Login pass. to $pass1 = 'admin';//Login pass.

    At the moment your $pass1 isn't actually defined.

  4. #4
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default

    *feels dumb.
    *sobs.

    Thanks, fixed, works fine. +Rep to Tomm.
    i've been here for over 8 years and i don't know why

  5. #5
    Join Date
    Feb 2005
    Location
    Leicestershire / Sheffield
    Posts
    685
    Tokens
    0

    Default

    you should use

    ===

    as in
    PHP Code:
    if($password === $pass1){ 
    === means idenctal to,

    this way it will check caps in your pass
    ie;

    password == PaSSwOrD //Returns true,
    password === PaSSwOrD //Returns false,

  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Um, you can just use "==" as that is also case-sensitive. Or it is atleast in the PHP Version(s) I've used/using...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •