2

I'd really appreciate some help. I realise this sort of thing is asked, but I can't find a similar enough question to solve my problem.

We have above two tables in our database named Account and Count. What we need is to compare username & password from account table so that user can login & then need to get his respective user_id from count table.

Account table contains id, username and password . Count table contains user_id and point.

Account: 
ID  |  username  |    password   |   email
--------------------------------------------                   
1   |  sample1   |    ***        |   abc@gmail.com         

Count:
user_id  |   friends   |   point
---------------------------------                
1        |    99       |    80

Now the problem is we need the above solution with our current code below .....

LOGIN -----------------
if($formAction == "login") {
    //VERIFY IF THE USERNAME ALREADY EXIST
    $SQL = "SELECT * FROM Accounts WHERE username = '" . $username . "'";

    //GIVE THE RESULT
    $result_id = @mysql_query($SQL) or die("DATABASE ERROR!");
    $total = mysql_num_rows($result_id);

    if($total) {
        $datas = @mysql_fetch_array($result_id);                
        if(!strcmp($password, $datas["password"])) {
            if($emailActivation == "true") {
                click on his activation link                        
                if($datas["activated"] == 1) {                          
                        echo "IMCONNECTED";
                    } 
                else {
                        echo "ACCOUNT_NOT_ACTIVATED";
                    }
                } 
                else if($emailActivation == "false") {                      
                    echo "IMCONNECTED";
                }
            } 
            else {  
                echo "WRONG_PASSWORD";
            }
        } 
        else {              
            echo "User not found!";
        }       
    } //END OF LOGIN ACTION

So could anyone help me out in getting the solution as how to get user_id from count table via passing a query in the above login php code.

The code on my post allow me to access all the details about the user after login such as email from the Accounts table, but what i want is to pass a query for 'count' table in such a way so that i can access information about that particular user id such a 'friends' or 'point' from count table.

Can anyone please help me out. I don't know much php so i need complete code.

Ranjan Roy
  • 21
  • 3

1 Answers1

0
    if(!strcmp($password, $datas["password"])) {

        $res = mysql_query("SELECT * FROM `Count` WHERE `user_id`='".$datas['id']."';") or die(mysql_error());
        $row = mysql_fetch_assoc($res);

        # here you have it, do what you need
        $user_id = $row['user_id'];
jmp
  • 2,456
  • 3
  • 30
  • 47