Jump to content


Photo

Problem making a login function within a class...


  • Please log in to reply
4 replies to this topic

#1 Razzeal

Razzeal
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 April 2006 - 09:38 PM

Hey,

I was trying to make a function (within a class) for logging in, this to make it easier on my websites to log in and not have to create al the code over and over again.

Now my problem is here:

$v_user = mysql_query("SELECT * FROM $u_table WHERE $u_row = $username") or die("Error: " .mysql_error());

The error I get is a mysql error, saying I should check my code considering the "'WHERE = '" on line 1.... Is it possible to have variables in my sql like this or do I have to change the constants every time I use the function for another website? How else should I put the variables so that ik might still work.

Thx in advance,

Razzeal...

#2 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 April 2006 - 09:43 PM

I almost NEVER code in OOP, but if you are using this inside a class it should be:

$this->$v_user = mysql_query("SELECT * FROM $u_table WHERE $u_row = $username") or die("Error: " .mysql_error());

or

$this::$v_user = mysql_query("SELECT * FROM $u_table WHERE $u_row = $username") or die("Error: " .mysql_error());


#3 Razzeal

Razzeal
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 01 May 2006 - 07:17 AM

Thx for your reply!

I tried your code and it kept returning the same error this is my function:

function login($username, $password)
{

        //controleren of ingevulde username bestaat:
         $this -> $v_user = mysql_query("SELECT * FROM $u_table WHERE $u_row = '$username'") or die("Error: " .mysql_error());
         $exist = mysql_num_rows($v_user);

    if($exist < 1)
       {
               $error = "Username not found!";
               return $error;

       } else {

              //wachtwoord controleren:
               $this->$get_pass = mysql_query("SELECT * FROM $u_table WHERE $u_row = '$username'") or die("Error: " .mysql_error());
               $p_array = mysql_fetch_array($get_pass);
               $e_pass = $p_array["password"];

               if($e_pass != md5($password))
                  {
                         //errors weergeven:
                          $error = "Wrong Password!";
                          return $error;

                  } else {
                         //login gelukt!
                          return true;
                          }

       }
}

I would like to keep it als variable is possible so that i can use this function wherever I want :D

Thx

#4 rawb

rawb
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 01 May 2006 - 07:50 AM

Make sure you are using the 'this->' keyword to reference your variables!

#5 Razzeal

Razzeal
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 01 May 2006 - 09:20 AM

That means before every variable? anyway I think I got it now :D thx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users