Jump to content

Recommended Posts

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']';

Link to comment
https://forums.phpfreaks.com/topic/236882-t_constant_encapsed_string/
Share on other sites

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}'

 

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'];

// 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.

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

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

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.

// 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..

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.