Jump to content

passing session variables in a query


grantp22

Recommended Posts

Hi

 

Can somebody please give me the corect syntax for the following query, I am finding it difficult to pass the username of a session in a query. I have tried so many ways to implement this, but it just won't work...

 

These are some of the methods I have tried! What am I doing wrong. It's in PHP by the way!

 

   $q = "SELECT user, message, senttime "
       ."FROM ".TBL_AUCTION_RESPONSES." WHERE user=".$session->username." ORDER BY senttime DESC";

   $q = "SELECT user, message, senttime "
       ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='.$session->username.' ORDER BY senttime DESC";

   $q = "SELECT user, message, senttime "
       ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='<?php echo $session->username;?>' ORDER BY senttime DESC";

 

 

If I use a string in the query as seen below in bolded letters, the query works just fine!

 

 

$q = "SELECT user, message, senttime "

      ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='grant' ORDER BY senttime DESC";

 

 

Can somebody tell me what the syntax should be for variables in a case like this

 

Thanks

Grant

Link to comment
https://forums.phpfreaks.com/topic/179279-passing-session-variables-in-a-query/
Share on other sites

davidAM

 

I tried that out, it doesn't work either, it's something to do with the syntax. Should it be single quotes doubles, should it be structured differently, I tried so many different ways, it just won't work but should.

 

Thanks for teaching me something, I never knew session variables were stored in an array,, i'm only using php and mysql for 3 weeks now!

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.