adi123 Posted May 11, 2011 Share Posted May 11, 2011 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; } } } } ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 12, 2011 Share Posted May 12, 2011 That's great, you pasted in two class definitions. Where is your code that is actually using these classes, and what did you try already that doesn't work? Quote Link to comment Share on other sites More sharing options...
adi123 Posted May 12, 2011 Author Share Posted May 12, 2011 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); Quote Link to comment Share on other sites More sharing options...
adi123 Posted May 12, 2011 Author Share Posted May 12, 2011 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. Quote Link to comment Share on other sites More sharing options...
adi123 Posted May 13, 2011 Author Share Posted May 13, 2011 SOLVED THE PROBLEM WITHOUT ANY HELP FROM THIS WEBSITE>... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.