Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.