Jump to content


Photo

Help with Query


  • Please log in to reply
2 replies to this topic

#1 Loathorhealer

Loathorhealer
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 March 2006 - 12:50 AM

if ($logged_in == 1) {
    echo 'welcome back '.$_SESSION['username'].'';
 $query = sprintf("SELECT firstname, lastname FROM users WHERE ("$logged_in == 1")");


$result = mysql_query($query);
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
}

while ($row = mysql_fetch_field($result)) {
   echo $row['firstname'];
   echo $row['lastname'];
}
mysql_free_result($result);


okay. I get this error

Parse error: syntax error, unexpected T_VARIABLE in /home/.navy/loathor/squaresyndicate.com/welcome.php on line 13

and I know its becuase of the $logged_in <-- deal. but I need it to display the firstname and the lastname of the person Just logged in. can you help?



#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 25 March 2006 - 06:26 PM

[!--quoteo(post=358109:date=Mar 25 2006, 12:50 AM:name=Loathorhealer)--][div class=\'quotetop\']QUOTE(Loathorhealer @ Mar 25 2006, 12:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if ($logged_in == 1) {
    echo 'welcome back '.$_SESSION['username'].'';
 $query = sprintf("SELECT firstname, lastname FROM users WHERE ("$logged_in == 1")");
$result = mysql_query($query);
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
}

while ($row = mysql_fetch_field($result)) {
   echo $row['firstname'];
   echo $row['lastname'];
}
mysql_free_result($result);
okay. I get this error

Parse error: syntax error, unexpected T_VARIABLE in /home/.navy/loathor/squaresyndicate.com/welcome.php on line 13

and I know its becuase of the $logged_in <-- deal. but I need it to display the firstname and the lastname of the person Just logged in. can you help?
[/quote]

What is actually stored in the variable $logged_in?
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 25 March 2006 - 06:53 PM

Is there a session variable for a userid or something?
Then you can just do your query like so:
$query = sprintf("SELECT firstname, lastname FROM users WHERE userid = '".$_SESSION['userid']."'");

Personal site: NewEnigma  |  Java and JSF Discussion




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users