Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » PHP




 Page 1 of 1 [ 5 posts ] 



Author Message
 Post subject: passin da session vars in a query
 Post Posted: Thu Nov 12, 2009 11:03 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
Hi

could snebody !~!1please give me da exact syntax 4 da followin query,
I am findin it a bit tough!! 2 pass da username of a session in a query.
I hm tryin in so many ways 2 resolve dis ,however it just won't work...

These were sum of da methods I have tried! wer did i went wrong. It was
in the PHP by da way!

Code:
Code: 
   $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!

Code:

$q = "SELECT user, message, senttime "
       ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='grant' ORDER BY senttime DESC";


could somebody tell me wat da syntax should be 4 da variables in a
case like dis!!!

Thanks


Top 
 Post subject: Re: passin da session vars in a query
 Post Posted: Thu Nov 12, 2009 11:04 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Session vars r stord as an array:

Code:
$q = "SELECT user, message, senttime "
       . "FROM " . TBL_AUCTION_RESPONSES . " WHERE user=" . $_SESSION['username'] . " ORDER BY senttime DESC";


Top 
 Post subject: Re: passin da session vars in a query
 Post Posted: Thu Nov 12, 2009 11:04 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
I tried dat out, it does not work either, it was somethin 2 do wid da
syntax. Should it b single quotes doubles, should it be structurd differently,
I have tried so many diff ways, it just did not work but should.

Thanks for teachin me something, I never knew session variables generally
stored in an array,, i'm only usin a php nd mysql 4 3 weeks now!


Top 
 Post subject: Re: passin da session vars in a query
 Post Posted: Thu Nov 12, 2009 11:05 am 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
Try

Code:
$q = "SELECT user, message, senttime FROM " . TBL_AUCTION_RESPONSES . " WHERE user='" . $_SESSION['username'] . "' ORDER BY senttime DESC";


Top 
 Post subject: Re: passin da session vars in a query
 Post Posted: Thu Nov 12, 2009 11:05 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
thanks for the responses guyssss


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 5 posts ] 




Board index » Server Side Development » PHP


Who is online

Users browsing this forum: No registered users and 2 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron