Page 1 of 1

Php Output Query, Help Required...

Posted: Fri May 15, 2009 4:24 pm
by MrNeDev
Hiya people,

No surprise but I require some help with a small piece of PHP…

Aim: What I’m trying to do is grab the username that is stored within Session information, and then pass this into my Sql query, so I’d have something along the lines of this

Code: Select all

$sql = 'SELECT * FROM reviews WHERE Reviewer = "SESS_LOGIN";

Reason: I’m trying to feed data into a page that is only associated with the user who is browsing, for example, if I was designing a profile page then, I would only want the user to be capable of editing their own information and as a result should only be able to view there own information.

What I know: Well, to be honest not very much in PHP but if I use the following line, I know it can echo the relevant information through to the page and print the user name. This information is assigned to the session within the authentication page that was created which sets up the session/cookie.

Code: Select all

<?php echo $_SESSION['SESS_LOGIN'];?>
So how would I achieve the option of assigning the username from the session and feeding it directly into my Sql statement?

Any help would be greatly appreciated people.

Regards,
Marcus

Re: Php Output Query, Help Required...

Posted: Fri May 15, 2009 4:29 pm
by Chrisaster
You forgot to close your query string :)

Code: Select all

 $sql = 'SELECT * FROM reviews WHERE Reviewer = "SESS_LOGIN"';

Re: Php Output Query, Help Required...

Posted: Fri May 15, 2009 4:36 pm
by MrNeDev
Thanx man,

Unfortunately that was not the answer i was looking for. I managed to the the answer on another forum and it was as follows.

Code: Select all

$sql = "SELECT * FROM reviews WHERE Reviewer = '" . $_SESSION['SESS_LOGIN'] . "'";