Building queries with session variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chrisoftoday@googlemail.com

    #1

    Building queries with session variables

    I'm quite new to PHP so apologies if this is a really simple problem.
    I'm using a session variable to store a userID after login and trying
    to build a query using this variable. I have session_start() at the top
    of each page and have registered the variable like so ($username is an
    e-mail address taken from some user input)...

    $user=$username ;
    session_registe r("user");

    By echoing it on each page I can see that the $user session variable is
    correctly passed through several pages (where it doesn't get used), but
    when I come to actually use it to build a query using the following
    line of code...

    $getmovlist="SE LECT movTitle, movYear FROM movie WHERE movID=(SELECT
    movID FROM fMovie WHERE uID='" .$user ."')";

    .... the query which is constructed is...

    SELECT movTitle, movYear FROM movie WHERE movID=(SELECT movID FROM
    fMovie WHERE uID='cxi03u')

    which returns nothing as the end of the email address (@cs.nott.ac.uk )
    has been cut off. If I echo the variable before inserting it into the
    query it outputs the variable correctly (cxi03u@cs.nott .ac.uk)
    alongside the incorrect query, but then if I refresh the page the value
    of the variable has changed to cxi03u.

Working...