Jump to content

cannot get user id after login


adi123

Recommended Posts

I am trying to get the user id after login so i can get data from another table with the same user id.

 

heres my code.

 

membership.php

 

<?php

 

require 'Mysql.php';

 

class Membership {

 

function getCustId($un, $pwd) {

 

$con = mysql_connect("DB_SERVER","DB_USER","DB_PASSWORD");

mysql_select_db("DB_NAME", $con);

if (!$con)

{

die('Could not connect: '.mysql_error());

}

    //$customer_id="";

$sql = "SELECT id FROM login WHERE username ="."$un";

$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {

  $customer_id=$row{'customer_id'};

  echo $customer_id;

}

 

mysql_close($con);

 

return $customer_id;

$postid = $_POST['customer_id'];

}

 

function validate_user($un, $pwd) {

$mysql = New Mysqlcon();

$ensure_credentials = $mysql->verify_Username_and_Pass($un, md5($pwd));

$customer_id = $_GET['customer_id'];

/*error_log(1,"#### customer ID=$customer_id","0");

if($customer_id) {

$_SESSION['customer_id'] = $customer_id;

}*/

 

if($ensure_credentials) {

$_SESSION['status'] = 'authorized';

$_SESSION['username'] = ucfirst($un);

 

//$ref = $_SERVER['http_referrer'];

//header( 'refresh: 5; url='.$ref);

 

header("location: ../cart/checkout.php?name=$un&id=$customer_id");

} else return "Please enter a correct username and password";

 

}

 

function log_User_Out() {

if( isset($_SESSION['status']) && isset($_SESSION['username']) ) {

unset($_SESSION['status']);

unset($_SESSION['username']);

if(isset($_COOKIE[session_name()]))

setcookie(session_name(), '', time() - 1000);

session_destroy();

}

}

 

function confirm_Member() {

session_start();

if($_SESSION['status'] !='authorized') header("location: ../login/login.checkout.php");

}

}

?>

 

 

 

mysql.php

 

 

 

<?php

 

class Mysqlcon {

private $conn;

 

function __construct() {

$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or

  die('There was a problem connecting to the database.');

}

 

function verify_Username_and_Pass($un, $pwd) {

 

$query = "SELECT *

FROM login, customerDetails

WHERE username = ? AND pwd = ? AND login.id = customerDetails.id

LIMIT 1";

 

if($stmt = $this->conn->prepare($query)) {

$stmt->bind_param('ss', $un, $pwd);

$stmt->execute();

 

if($stmt->fetch()) {

$stmt->close();

 

return true;

}

}

 

}

 

}

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/236104-cannot-get-user-id-after-login/
Share on other sites

this is the code on the login page

 

require_once 'dbcon.php';

require_once 'Membership.php';

 

$membership = new Membership();

 

// If the user clicks the "Log Out" link on the index page.

if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {

$membership->log_User_Out();

}

 

// Did the user enter a password/username and click submit?

if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {

$response = $membership->validate_User($_POST['username'], $_POST['pwd']);

}

 

 

this is the code after login, where it should get id of the user

 

echo $membership->getCustId($un, $pwd);

I have tried debugging the sql statement.

 

On the checkout page i get the error :

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Membership.php on line 18

 

All i need is the id of the user from login to be passed to the checkout page, so i can get user info from the details table.

 

 

can someone please provide some help, on getting the id.

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.