Jump to content

Problem making a login function within a class...


Razzeal

Recommended Posts

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:

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

The error I get is a mysql error, saying I should check my code considering the "[b]'WHERE = '[/b]" 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...
Link to comment
Share on other sites

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

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

or

[code]
$this::$v_user = mysql_query("SELECT * FROM $u_table WHERE $u_row = $username") or die("Error: " .mysql_error());
[/code]
Link to comment
Share on other sites

Thx for your reply!

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

[code]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;
                          }

       }
}[/code]

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

Thx
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.