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
https://forums.phpfreaks.com/topic/67868-capture-customer_id-from-login/
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;
}

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;
   }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.