Loging Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phyburn

    Loging Script

    It seems there is something wrong with my script for the reason that
    it always returns, UserName NOT found . I know it connects to the db
    fine because I don't get a error. So just been trying to figure out
    what's wrong. I am using PEAR btw.

    Pastebin: http://pastebin.ca/360410


    <?PHP

    require 'DB.php';


    $db = DB::connect('my sql://lol:lol@localho st/user');

    if (DB::isError($d b)) {die('ERROR{1}: ' . $db-
    >getMessage() ); }else{print "We connected";}
    $user = $_POST['user'];
    $password = md5($_POST['password']);
    $password2 = md5($_POST['password2']);

    $sql = check();



    function check()
    {
    global $db;
    global $user;


    $rows = $db->getAll('SELE CT user_name FROM user');
    if (DB::isError($d b)) {die('ERROR{2}: ' . $db->getMessage()); }



    if($user){
    if(array_key_ex ists("$user", $rows)){print "<p><b>User Name
    AcceptED</b>";}else{prin t "<p><b>User Name NOT found</b>";}

    }else{print "<p>no username was typed";}

    }

    ?>

  • Colin McKinnon

    #2
    Re: Loging Script

    phyburn wrote:
    It seems there is something wrong with my script for the reason that
    it always returns, UserName NOT found . I know it connects to the db
    fine because I don't get a error. So just been trying to figure out
    what's wrong. I am using PEAR btw.
    >
    By the time it got to me this had some very unusual formatting - I'd
    recommend sticking to the PEAR style guidelines, particularly when posting
    to newsgroups.
    if(array_key_ex ists("$user", $rows)){
    print "<p><b>User Name AcceptED</b>";
    You should be looking for a value, not a key - and getAll returns a nested
    array - i.e. somewhere there should be...

    $rows[$row_number]['username']==$user

    But really you should be checking this in the SQL - not loading a list of
    all users then checking in PHP.

    C.

    Comment

    • Rik

      #3
      Re: Loging Script

      On Sat, 17 Feb 2007 14:13:22 +0100, phyburn <phyburn@gmail. comwrote:
      It seems there is something wrong with my script for the reason that
      it always returns, UserName NOT found . I know it connects to the db
      fine because I don't get a error. So just been trying to figure out
      what's wrong. I am using PEAR btw.
      >
      Pastebin: http://pastebin.ca/360410
      >
      >
      <?PHP
      >
      require 'DB.php';
      >
      >
      $db = DB::connect('my sql://lol:lol@localho st/user');
      >
      if (DB::isError($d b)) {die('ERROR{1}: ' . $db-
      >getMessage() ); }else{print "We connected";}
      >
      $user = $_POST['user'];
      $password = md5($_POST['password']);
      $password2 = md5($_POST['password2']);
      >
      $sql = check();
      >
      >
      >
      function check()
      {
      global $db;
      global $user;
      >
      >
      $rows = $db->getAll('SELE CT user_name FROM user');
      if (DB::isError($d b)) {die('ERROR{2}: ' . $db->getMessage()); }
      Untested, I seldomly use PEAR::DB:

      $stmt = $db->prepare('SELEC T user_name, password FROM user WHERE user_name
      = ?');
      $result = $db->execute($stmt, $user);
      if($result->numRows()!=1 ) die('Username not found or multiple users with
      the same name.');
      --
      Rik Wasmus

      Comment

      Working...