Jump to content

Capture customer_id from login


coop

Recommended Posts

Hi all,

 

I'm developing a shopping cart application using php/MySQL and a flash front end but I'm syure the information I'm looking for would e the same if it was html.

 

I wanted to capture the Customer_id of a customers table when people login, so when people login in successfully there customer_id will be captured and sent back to flash (if I can work out how to echo the result I can send it back to flash)

 

//Call the functions
if(isset($_POST["action"])){
   switch($_POST["action"]){  
      case "login":
         $result = login($_POST['username'],$_POST['pass']);
         echo "user=" . $result;
         break;
case "register":
    $result = register($_POST['username'],$_POST['pass'],$_POST['email']);
    echo $result;
    break;
      case "new_password":
         $result = new_password($_POST['email']);
         echo $result;
         break;		
   }
}
//
//Login
function login($username,$pass){
   GLOBAL $db,$table;
   $username = trim($username);
   $pass = md5(trim($pass));
   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'");
   $id_query = mysql_query("SELECT userID FROM $table WHERE userName = '$username' AND userPassword = '$pass'");// My attempt to capture the id
   return mysql_num_rows($query);
// capture the customer_id
}

Link to comment
Share on other sites

I tried this but no luck, and now the user variable isn't being passed.

 

Is this the correct way tto capture the userid and then pass it ut of the function ?

 

//
//Call the functions
if(isset($_POST["action"])){
   switch($_POST["action"]){  
      case "login":
          $result = login($_POST['username'],$_POST['pass']);
        //echo "user=" . $result;
     echo "&user=" . $result . "&custID" . $cust_id;
          break;
case "register":
    $result = register($_POST['username'],$_POST['pass'],$_POST['email']);
    echo $result;
    break;
      case "new_password":
         $result = new_password($_POST['email']);
         echo $result;
         break;		
   }
}
//
//Login
function login($username,$pass){
   GLOBAL $db,$table;
   $username = trim($username);
   $pass = md5(trim($pass));
   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'");
   $cust_id = mysql_query("SELECT userID FROM $table WHERE userName = '$username' AND userPassword = '$pass'"); 	
   return mysql_num_rows($query);
   return $cust_id;
}

Link to comment
Share on other sites

you have already retrieved the data you want with the first query...

 

<?php

function login($username,$pass){
   GLOBAL $db,$table;
   $username = trim($username);
   $pass = md5(trim($pass));
   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'");
   if (mysql_num_rows($query) == 1)
   {
    $data = mysql_fetch_assoc($query);
    return $data['userID'];
   }
   else
   {
    return false;
   }
}
?>

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.