?
Solved

Query by Session Variable

Posted on 2010-01-02
2
Medium Priority
?
253 Views
Last Modified: 2013-12-12
i need to filter my recordset by a session variable that is stored in " $_SESSION['_amember_user']"
This variable contains entire customer record as array and so also the member ID.

But somehow the code below does not seem to find the specific record for the member ID.

The session variable works fine as I can just use another code like

<?php
session_start();
$user = $_SESSION['_amember_user'];
if ($user['member_id'] > 0){
    print "Hello $user[name_f] $user[name_l] <br>\n";
} else {
    print "You are not logged-in";
}

that works just fine however the query does not!

Any ideas what I am doing wrong? Thank you
<?php
session_start();
$member_id = $_SESSION['_amember_user']['member_id'];

$colname_sessionID = "-1";
if (isset($_SESSION['_amember_user']['member_id'])) {
  $colname_sessionID = (get_magic_quotes_gpc()) ? $_SESSION['_amember_user']['member_id'] : addslashes($_SESSION['_amember_user']['member_id']);
}
mysql_select_db($database_inburn, $inburn);
$query_sessionID = sprintf("SELECT * FROM amember_members WHERE member_id = %s", GetSQLValueString($colname_sessionID, "int"));
$sessionID = mysql_query($query_sessionID, $inburn) or die(mysql_error());
$row_sessionID = mysql_fetch_assoc($sessionID);
$totalRows_sessionID = mysql_num_rows($sessionID);
?>

Open in new window

0
Comment
Question by:michael789
2 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26162637
Hello michael789,

Try :


<?php
session_start();
$member_id = $_SESSION['_amember_user']['member_id'];

$colname_sessionID = "-1";
if (isset($_SESSION['_amember_user']['member_id'])) {
  $colname_sessionID = (get_magic_quotes_gpc()) ? $_SESSION['_amember_user']['member_id'] : addslashes($_SESSION['_amember_user']['member_id']);
}
mysql_select_db($database_inburn, $inburn);
$query_sessionID = "SELECT * FROM amember_members WHERE member_id = " . $colname_sessionID;
$sessionID = mysql_query($query_sessionID, $inburn) or die(mysql_error());
$row_sessionID = mysql_fetch_assoc($sessionID);
$totalRows_sessionID = mysql_num_rows($sessionID);
?>

Open in new window

0
 

Accepted Solution

by:
michael789 earned 0 total points
ID: 26162804
no...sorry. does not work however i tried this and itworked now:

$colname_sessionID2 = "-1";
if (isset($member_id2)) {
  $colname_sessionID2 = (get_magic_quotes_gpc()) ? $member_id2 : addslashes($member_id2);
}
mysql_select_db($database_inburn, $inburn);
$query_sessionID2 = sprintf("SELECT * FROM amember_members WHERE member_id = %s", GetSQLValueString($colname_sessionID2, "int"));
$sessionID2 = mysql_query($query_sessionID2, $inburn) or die(mysql_error());
$row_sessionID2 = mysql_fetch_assoc($sessionID2);
$totalRows_sessionID2 = mysql_num_rows($sessionID2);

thank you anyway. happy new year to you
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question