PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
markkam
Forum Newbie
Posts: 3 Joined: Wed Aug 28, 2002 12:56 pm
Post
by markkam » Wed Aug 28, 2002 12:56 pm
Any Idea why this code wont work?
Code: wrote:
$sql="SELECT * FROM users WHERE username=$_SESSION['username']";
$result=db_query($sql);
if (db_result($result,0,'is_admin') == '1') {
include("templates/adminmenu.inc");
}
I get the error
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
JPlush76
Forum Regular
Posts: 819 Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:
Post
by JPlush76 » Wed Aug 28, 2002 1:23 pm
well my first thought would be #1 username probably isn't a numeric only field so you would need quotes ' ' around your username variable
try this
Code: Select all
$username = $_SESSIONї'username']";
$sql="SELECT * FROM users WHERE username = '$username'"
markkam
Forum Newbie
Posts: 3 Joined: Wed Aug 28, 2002 12:56 pm
Post
by markkam » Wed Aug 28, 2002 1:41 pm
Im pulling username from session data, not from a header or the like, which is how I am passing variables.
I need to be able to do it with the SESSION data for username.
JPlush76
Forum Regular
Posts: 819 Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:
Post
by JPlush76 » Wed Aug 28, 2002 1:45 pm
thats what the $_SESSION['yoursessionvariable'] does
http://www.php.net/manual/en/ref.session.php
from the php.net manual:
Code: Select all
Use of $_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended for security and code readablity. With $_SESSION or $HTTP_SESSION_VARS, there is no need to use session_register()/session_unregister()/session_is_registered() functions. Users can access session variable like a normal variable
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Aug 28, 2002 2:18 pm
you may avoid the assignment
Code: Select all
$username = $_SESSIONї'username']";if you use this syntax
Code: Select all
$sql="SELECT * FROM users WHERE username='{$_SESSIONї'username']}'";
only if you like to
markkam
Forum Newbie
Posts: 3 Joined: Wed Aug 28, 2002 12:56 pm
Post
by markkam » Wed Aug 28, 2002 2:22 pm
volka wrote: you may avoid the assignment
Code: Select all
$username = $_SESSIONї'username']";if you use this syntax
Code: Select all
$sql="SELECT * FROM users WHERE username={$_SESSIONї'username']}";
only if you like to
Thank you!!! I've been beating myself over the head with a copy of windows trying to figure it out.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Aug 28, 2002 2:25 pm
windows installation cd or the book "just the bugs"?
phpPete
Forum Commoner
Posts: 97 Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey
Post
by phpPete » Wed Aug 28, 2002 3:21 pm
OT
Volka wrote...
windows installation cd or the book "just the bugs"?
Thats either a lot of CDs or a one heavy book!
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Wed Aug 28, 2002 3:24 pm
Even more OT
Would such a book be liftable? I'ld be worried about it unbalancing the gravitation forces in our solar system....