Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STR

hi guys

I know this is very basic.

But this codes below has something wrong,

$sql="select count('.$postConfig['id'].') as numRows from '$crudTableName' WHERE username='$username'";

Thanks in advanced.

echo $sql onto the page, so you get to see what PHP has substituted for those variables.

Check it carefully, then copy the echoed text, paste it into whatever you manage your database with and see if it throws any errors, or if you have any matching data in your database.

Its the only way you will work out if your HTML form, your PHP, your SQL statment or your data is to blame.


$sql="select count(".$postConfig['id'].") as numRows from 
$crudTableName WHERE username='$username'";

$username is a string so you quote it, $postconfig is an array, so you need to concat the value, $crudtablename is a scalar value so you can leave it inside double quotes and PHP will expand it.

Here you go, it just looks like you were getting a little confused with what quotes you should’ve been using. :slight_smile:

$sql = 'select count(' . $postConfig['id'] . ") as numRows from '$crudTableName' WHERE username='$username';";

Edit: Great catch Cups.


Thank you alleluia it’s fixed now.

You are an angel man.

THank you, thank you, thank you !!!