NLT Posted May 19, 2011 Share Posted May 19, 2011 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\hk\config.php on line 22 Code: <?php // require the hotels config file require "../config.php"; // start the sessions session_start(); // check if the user is signed in if(!isset($_SESSION['username'])) { Header("Location: ../index.php?error=signedout"); } elseif(!isset($_SESSION['account'])) { Header("Location: ../index.php?error=signedout"); } // process all the queries in here // do the user related ones $assoc = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'")); $username = $assoc'['username']'; $ranknum = $assoc['rank']; // parse the rank $parseRank = mysql_fetch_assoc(mysql_query("SELECT * FROM ranks WHERE id = '{$ranknum}' $rank = $parseRank['name']; // get server status $sStatus = mysql_fetch_assoc(mysql_query("SELECT * FROM server_status")); $usersonline = $sStatus['users_online']; $roomsloaded = $sStatus['rooms_loaded']; $status = $sStatus['status']; echo $assoc['rank']; exit(); if($assoc['rank'] < 6) { header("Location: ../index.php"); } ?> On line 22; $username = $assoc'['username']'; Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/ Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 Your quotes are the wrong way round $username = $assoc['username']; Also this line will return an error too because you have left off ")); at the end of it $parseRank = mysql_fetch_assoc(mysql_query("SELECT * FROM ranks WHERE id = '{$ranknum}' Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217648 Share on other sites More sharing options...
NLT Posted May 19, 2011 Author Share Posted May 19, 2011 Thank you for your quick reply! I'm a beginner, so I might come here and ask a lot. Now, I got this; Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\hk\config.php on line 30 $sStatus = mysql_fetch_assoc(mysql_query("SELECT * FROM server_status")); // get server status $sStatus = mysql_fetch_assoc(mysql_query("SELECT * FROM server_status")); $usersonline = $sStatus['users_online']; $roomsloaded = $sStatus['rooms_loaded']; $status = $sStatus['status']; Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217650 Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 Also this line will return an error too because you have left off ")); at the end of it $parseRank = mysql_fetch_assoc(mysql_query("SELECT * FROM ranks WHERE id = '{$ranknum}' Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217652 Share on other sites More sharing options...
NLT Posted May 19, 2011 Author Share Posted May 19, 2011 // parse the rank $parseRank = mysql_fetch_assoc(mysql_query("SELECT * FROM ranks WHERE id = '{$ranknum}'")) $rank = $parseRank[name]; Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\hk\config.php on line 27 As soon as this config is done, I should be able to get on with it. Sorry about this. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217654 Share on other sites More sharing options...
wildteen88 Posted May 19, 2011 Share Posted May 19, 2011 You have left off the semi-colon at the end of the line. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217661 Share on other sites More sharing options...
NLT Posted May 19, 2011 Author Share Posted May 19, 2011 Ahh, just noticed. Now, I did that, and I get more errors, great. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hk\config.php on line 21 Notice: Use of undefined constant username - assumed 'username' in C:\xampp\htdocs\hk\config.php on line 22 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hk\config.php on line 26 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hk\config.php on line 30 Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217666 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 i would break it down into a few more lines than you are using. e.g $assoc = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'")); $username = $assoc'['username']'; $ranknum = $assoc['rank']; change to $query = mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'"); $assoc = mysql_fetch_assoc($query); $username = $assoc['username']; $ranknum = $assoc['rank']; also, the mysql_fetch_assoc() errors you are receiving is because your queries are not correct. The undefined constant error is most likely due to your query failing Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217677 Share on other sites More sharing options...
NLT Posted May 19, 2011 Author Share Posted May 19, 2011 <?php $host = "localhost"; $username = "root"; $password = ""; $dbname = "phoenix3"; $currentstyle = "Default"; $sitemail = 'yourmail@yourmail.tld'; $twitter = ""; //Twitter account $language = 'en'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217680 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 Undefined constant warnings are caused by undefined constants. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217684 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 Undefined constant warnings are caused by undefined constants. however a constant isn't called in his script therefore the parser must be confused by his syntax.. since hes trying to call out username from his query but his query is failing Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217685 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 Syntax doesn't "confuse" the parser. There's an undefined constant being used in the code. The revised code needs to be posted, from the beginning to a point at least a few lines past the last indicated error/warning. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217692 Share on other sites More sharing options...
mikosiko Posted May 19, 2011 Share Posted May 19, 2011 // do the user related ones $assoc = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'")); $username = $assoc'['username']'; $ranknum = $assoc['rank']; the undefined constant.... Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217698 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 // do the user related ones $assoc = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'")); $username = $assoc'['username']'; $ranknum = $assoc['rank']; the undefined constant.... yep, i know where the constant is where the error is triggered..and ive provided an explanation...first step is to fix the query..which im guessing isnt working because $_SESSION['username'] is not set.. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217699 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 The query's success or failure has nothing to do with that error at all. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217700 Share on other sites More sharing options...
mikosiko Posted May 19, 2011 Share Posted May 19, 2011 that is not what you said before "however a constant isn't called in his script therefore the parser must be confused by his syntax" Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217701 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 The query's success or failure has nothing to do with that error at all. okay Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217702 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 The query's success or failure has nothing to do with that error at all. its trying to fetch a row that doesnt exist since the query is failing Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217709 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 For the last time, the query's success or failure has nothing to do with the error. Mikosiko already pointed out the cause of the error, and it is not related to the query in any way. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217777 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 And you'll se e that I corrected that error on one of my first posts Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217835 Share on other sites More sharing options...
Pikachu2000 Posted May 19, 2011 Share Posted May 19, 2011 And the new error is unrelated to the query as well. Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217842 Share on other sites More sharing options...
fugix Posted May 19, 2011 Share Posted May 19, 2011 You are right about the second error. Honestly didn't even see that he posted another error. My appologies to you pikachu Quote Link to comment https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/#findComment-1217852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.